Skip to main content

Maven3 JUnit4 java.lang.ClassFormatError: javax/persistence/Persistence

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
ruddy32
Offline
Joined: 2013-01-08

Hi,

While build a component using maven 3, the build fails at test step (JUnit4). I get the following error:

java.lang.ClassFormatError: javax/persistence/Persistence
at com.timm.mcr.persistence.PersistenceTest.setUpClass(PersistenceTest.java:30)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
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.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at com.sun.proxy.$Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

THe pom.xml include following lines:

		<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink.version}</version>
<scope>provided</scope>
</dependency>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>${glassfish.version}</version>
<scope>test</scope>
</dependency>

I'm using Eclipse Indigo SR2.

Have you any idea about the problem?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ruddy32
Offline
Joined: 2013-01-08

I fix the problem by removing this section

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>

and updating this one
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>${glassfish.version}</version>
<scope>provided</scope>
</dependency>
Romain Grecourt...
Offline
Joined: 2012-02-17

Hi,

Your issue might be related to the fact that
javax.persistence.Persistence class is present in the following
dependencies:

- javax:javax.javaee-api
- glassfish-embedded-all

You just need to make sure eclipselink is first in the test classpath.
Which is what you did by removing javaee-api and use scope=provided for
glassfish-embedded-all.

Note that javaee-api:6.0 contains stripped classes, it is only intended
for compilation *only*.

Thanks,
Romain

On 6/25/13 2:39 PM, forums@java.net wrote:
> I fix the problem by removing this section javax javaee-api
> ${javaee-api.version} provided and updating this one
> org.glassfish.main.extras glassfish-embedded-all ${glassfish.version}
> provided
>
> --
>
> [Message sent by forum member 'ruddy32']
>
> View Post: http://forums.java.net/node/897474
>
>

Romain Grecourt...
Offline
Joined: 2012-02-17

On 6/25/13 3:14 PM, Romain Grecourt wrote:
> Hi,
>
> Your issue might be related to the fact that
> javax.persistence.Persistence class is present in the following
> dependencies:
>
> - javax:javax.javaee-api
> - glassfish-embedded-all
>
> You just need to make sure eclipselink is first in the test classpath.
Here I meant to say glassfish-embedded, not eclipselink sorry for the
confusion.
> Which is what you did by removing javaee-api and use scope=provided
> for glassfish-embedded-all.
>
> Note that javaee-api:6.0 contains stripped classes, it is only
> intended for compilation *only*.
>
> Thanks,
> Romain
>
> On 6/25/13 2:39 PM, forums@java.net wrote:
>> I fix the problem by removing this section javax javaee-api
>> ${javaee-api.version} provided and updating this one
>> org.glassfish.main.extras glassfish-embedded-all ${glassfish.version}
>> provided
>>
>> --
>>
>> [Message sent by forum member 'ruddy32']
>>
>> View Post: http://forums.java.net/node/897474
>>
>>
>