Getting ClassNotFoundException org.eclipse.persist

2019-09-11 08:08发布

问题:

I'm trying to walk through the JPA-RS tutorials like:
http://java.dzone.com/articles/introducing-eclipselink-jpa-rs or
http://www.eclipse.org/eclipselink/documentation/2.5/solutions/restful_jpa.htm

But after trying to deploy (using the maven and glassfish plugin) the application on my glassfish I get the following error stacktrace:

WebModule[/rest]Servlet /rest threw load() exception java.lang.ClassNotFoundException: 
org.eclipse.persistence.jpa.rs.resources.MetadataResource at 
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1783) at
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1633
) at org.eclipse.persistence.jpa.rs.service.JPARSApplication.(JPARSApplication.java:62) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at 
...

I do not find the class in my imported dependencies:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.jpars</artifactId>
    <version>2.6.0</version>
</dependency>

By searching for that error, I getting no one who is sharing the same problem with me. Are you able to help me by getting an solution for that problem? Tell me if you need more conext/background information about the project.

Kind regards.

回答1:

Use your eclipselink dependencies of the same version: either both eclipselink and org.eclipse.persistence.jpars should be 2.6.0 or both should be 2.5.0.

When using 2.6.0 org.eclipse.persistence.jpa.rs.resources.MetadataResource is in the eclipselink.jar