Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class not found when using JAX-RS with Eclipse and Glassfish

I am using Eclipse Luna (versions 4.4.2) and Glassfish 4 to build a REST web-app using JAX-RS.

The following piece of code, which is just a very simple post to the REST api that was previously working just fine, has started throw a very strange error:

@POST
public Response addToWatchlist(WatchlistEntry watchlistentry)
{
    return Response.ok(watchlist_service.addToWatchlist(watchlistentry).toString()).build();
}

The error is below:

Warning: StandardWrapperValve[Jersey Web Application]: Servlet.service() for servlet Jersey Web Application threw exception
java.lang.ClassNotFoundException: javax.xml.parsers.ParserConfigurationException not found by org.eclipse.persistence.moxy

All I have been able to find out about this is this webpage: https://java.net/jira/browse/JERSEY-2888

One of the comments says this has been fixed in EclipseLink 2.6.1 and Jersey 2.19.

I am pretty new to using MAVEN and eclipse - assuming the above is correct, how do I get my Maven Project in Eclipse to update the Jersey version? Also how do I update the EclipseLink version? Their site only seems to have version 2.6.0 available: http://www.eclipse.org/eclipselink/#download

I assume all this can be done through eclipse itself?

All help appreciated!

EDIT 1: It seems like eclipselink 2.6.1 has been released on Oct 15th 2015, as you can see here: http://www.eclipse.org/eclipselink/releases/

However, as you can see here, it doesn't seem to have been incorporated into eclipse for "help -> update software": http://download.eclipse.org/rt/eclipselink/updates/

Which is highly annoying.

I am building my REST website, and no PUT or POST will work because of this error.

Does anybody know how to get 2.6.1 working? I am using a Maven jersey-quickstart-webapp Project.

This bug is a royal pain in the face.

EDIT 2: I've got a hack working today. When I check programmtically what version of eclipselink is being used at runtime like below, it tells me it is version 2.6.1, even though the bug remains:

Class<?> myClass = Class.forName("org.eclipse.persistence.Version");
Method myMethod = myClass.getMethod("getVersion");
String version = myMethod.invoke(null).toString();
System.out.println("version = " + version);

In a related question (How to find what version of EclipseLink my Eclipse Project is using?) I found out how to find the actual jar files glassfish is using for eclipse. They are in the glassfish/modules directory. Inside the org.eclipse.persistence.core.jar file has will be a readme.html which tells you the version of eclipselink that glassfish is using. For me it was 2.6.

I manually updated the org.eclipse.persistence.core.jar and the org.eclipse.persistence.moxy.jar file with the latest versions from the maven site. While this is quite hacky, as I don't know what else is effected by doing this, it does get over this problem. If I find out the correct way to do this, I will write an answer below, for all and sundry.

like image 487
Tom O'Brien Avatar asked Oct 14 '15 15:10

Tom O'Brien


4 Answers

Going through the Jersey JIRA and eclipse link website it seems like Eclipse link 2.6.1 is still under development i.e. not yet released. That's why its not available for download.

To use an updated version of Jersey in maven you need to give depending to the newer version 2.19 in your pom.xml.

But, since eclipse link 2.6.1 is yet to be released, even if you use newer version of Jersey it might be of little use. But still you can give it a try.

like image 66
Dhruv Rai Puri Avatar answered Nov 15 '22 08:11

Dhruv Rai Puri


To update version of jersey, find the following dependency and update the value of version tag in your pom.xml file

<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.22.1</version>
</dependency>
like image 2
Linh Nguyen Avatar answered Nov 15 '22 10:11

Linh Nguyen


Which server are you deploying your project into? I've had A LOT of problems with Glassfish 4.1.1 (incluiding that error). I downgraded to 4.1 and everything runs fine. It may be due to a problem with 4.1.1 newest modules (jars incluided in the server). I hope it helps. Its not the best solution but for me was a temporary workaround 'till I find which modules are failing.

like image 2
Bisonfan95 Avatar answered Nov 15 '22 09:11

Bisonfan95


The problem was solved by updating the version of eclipselink that glassfish was using. Eclipse updated it's version, but glassfish needs it's own update. The list of jar files that need to be placed in the glassfish/modules directory is given in this answer: How to change EclipseLink in GlashFish 4.0?

like image 1
Tom O'Brien Avatar answered Nov 15 '22 10:11

Tom O'Brien