ClassFormatError

I’m trying to use use diffDatabaseToChangeLog from ant and I get this error:

C:\Production\jboss_emr\LiquiBase\build.xml:64: java.lang.ClassFormatError: Illegal class name “javax.persistence/src/javax/persistence/PersistenceException” in class file javax/persistence/PersistenceException

Here’s my ant target:

   
       
        <diffDatabaseToChangeLog
                driver=“oracle.jdbc.OracleDriver}”
                url="${database.url}"
                username="${database.username}"
                password="${database.password}"
                referenceUrl=“hibernate:ejb3:emrEJB”
                outputFile="${hibernate.output.file}"
                classpathref=“liquibase.classpath”
        />
   

liquibase.classpath contains these jars:
      hibernate-commons-annotations-4.0.1.Final.jar
      lib/hibernate-core-4.1.4.Final.jar
      hibernate-entitymanager-4.1.4.Final.jar
      hibernate-envers-4.1.4.Final.jar
      liquibase-hibernate4.2-3.3.jar
      liquibase.jar
      ojdbc6.jar
      persistence-api-sources-2.0.jar
      snakeyaml-1.13.jar

If I removed persistence-api-sources-2.0.jar I get a ClassNotFoundException for PersistenceException.

I was running inside Eclipse, so to take that out of the picture I ran ant from the command line.  Ant version is 1.8.0.  Now I get this:

$ ant generateChangeLogFromEntities
Buildfile: C:\Production\jboss_emr\LiquiBase\build.xml

generateChangeLogFromEntities:
[diffDatabaseToChangeLog] WARNING 6/2/14 2:49 PM:liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath
[diffDatabaseToChangeLog] INFO 6/2/14 2:49 PM:liquibase-hibernate: Reading hibernate configuration hibernate:ejb3:emrEJB

BUILD FAILED
C:\Production\jboss_emr\LiquiBase\build.xml:119: java.lang.NoClassDefFoundError: javax/persistence/spi/ClassTransformer
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildConfigurationFromFile(HibernateEjb3Database.java:76)
        at liquibase.ext.hibernate.database.HibernateEjb3Database.buildConfiguration(HibernateEjb3Database.java:28)
        at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:43)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:123)
        at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseObject(BaseLiquibaseTask.java:263)
        at liquibase.integration.ant.DiffDatabaseTask.executeWithLiquibaseClassloader(DiffDatabaseTask.java:140)
        at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:71)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1212)
        at org.apache.tools.ant.Main.runBuild(Main.java:801)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.ClassTransformer
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1386)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1336)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1074)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        … 24 more

I had added all the jboss jars to classpathref for the diffDatabaseToChangeLog command, so it definitely includes the jar that has javax.persistence.spi.ClassTransformer.

Perhaps you could post an example build.xml that works using the EJB3 url. In addition I’m unclear how the hibernate integration finds the annotations in the entities.  Should the classpathref include the compiled java classes or does it need the sources?

Thanks

ClassFormatError is a strange error to get. Are you running against a too-old version of Java?

Nathan