Included a patch from Casey Link for a bug with custom naming-strategies
authorKai Moritz <kai@juplo.de>
Sat, 5 Nov 2016 16:22:42 +0000 (17:22 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 5 Nov 2016 16:26:32 +0000 (17:26 +0100)
pom.xml
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java

diff --git a/pom.xml b/pom.xml
index 85c629e..c92850c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <name>Andreas Kuhtz</name>
       <email>andreas.kuhtz@gmail.com</email>
     </contributor>
+    <contributor>
+      <name>Casey Link</name>
+      <email>casey@outskirtslabs.com</email>
+    </contributor>
     <!--
     <contributor>
       <name></name>
index f8c0634..c2ba9da 100644 (file)
@@ -1000,8 +1000,20 @@ public class Hbm2DdlMojo extends AbstractMojo
         getLog().debug("Explicitly set NamingStrategy: " + namingStrategy);
         try
         {
+          List runtimeClasspathElements = project.getRuntimeClasspathElements();
+          URL[] runtimeUrls = new URL[runtimeClasspathElements.size()];
+          for (int i = 0; i < runtimeClasspathElements.size(); i++)
+          {
+            String element = (String) runtimeClasspathElements.get(i);
+            runtimeUrls[i] = new File(element).toURI().toURL();
+          }
+          URLClassLoader newLoader = new URLClassLoader(
+              runtimeUrls,
+              Thread.currentThread().getContextClassLoader()
+              );
           @SuppressWarnings("unchecked")
-          Class<NamingStrategy> namingStrategyClass = (Class<NamingStrategy>) Class.forName(namingStrategy);
+          Class<NamingStrategy> namingStrategyClass =
+              (Class<NamingStrategy>) newLoader.loadClass(namingStrategy);
           config.setNamingStrategy(namingStrategyClass.newInstance());
         }
         catch (Exception e)