I cannot get the schemaexport Ant task to work. Though I have defined a classpath in the schemaexport task definition, I still have NoClassDefFoundErrors for classes that are in the task's classpath.
Suprisingly, it seems to work if I add the jars referenced in the schemaexport task definition to the ant runtime classpath...
So I guess this is a classloader issue with the SchemaExportTask.
If not, what is the point of defining a custom classpath for the schemaexport task if you also have to define it in Ant's runtime classpath !
Here is some of my configuration info :
Hibernate 3.0.5
Ant 1.6.5 (launched from Eclipse 3.1)
Build.xml snippet :
Code:
<target name="schemaExport">
<taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<path refid="project.classpath"/>
</classpath>
</taskdef>
<schemaexport config="${test.res.dir}/hibernate.cfg.xml" quiet="no" text="no" drop="no" delimiter=";" output="${build.dir}/schema-export.sql">
</schemaexport>
</target>
Please note that project.classpath contains hibernate3.jar and its related librairies.
However, I got this execution failure :
Code:
java.lang.NoClassDefFoundError: org/hibernate/type/ImmutableType
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1225)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/type/ImmutableType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.type.TypeFactory.heuristicType(TypeFactory.java:194)
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:259)
at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:128)
at org.hibernate.mapping.Column.getSqlType(Column.java:172)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:263)
at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:669)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:65)
at org.hibernate.tool.hbm2ddl.SchemaExportTask.getSchemaExport(SchemaExportTask.java:210)
at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:136)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
... 6 more
I would really appreciate any help, as I am thinking about to abandon this way of generating my DB schema and instead doing it at runtime via the hbm2ddl.auto configuration property...
Thanks,
Gregory