在Eclipse和Glassfish中使用JAX-RS时找不到类 [英] Class not found when using JAX-RS with Eclipse and Glassfish

查看:507
本文介绍了在Eclipse和Glassfish中使用JAX-RS时找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse Luna(版本4.4.2)和Glassfish 4使用JAX-RS构建REST Web应用程序。



以下代码段,这只是一个非常简单的帖子到REST api以前工作正常,已经开始抛出一个非常奇怪的错误:

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

错误在下面:

 警告:StandardWrapperValve [Jersey Web应用程序]:Servlet.service()为servlet Jersey Web应用程序抛出异常
java.lang.ClassNotFoundException:javax.xml.parsers。 ParserConfigurationException没有找到org.eclipse.persistence.moxy

我已经能够找到这个是这个网页:
https://java.net/jira/browse/JERSEY- 2888



其中一条评论说,这已经在EclipseLink 2.6.1和Jersey 2.19中修复。



我非常喜欢使用MAVEN和eclipse - 假设上述是正确的,我如何在Eclipse中获得我的Maven项目来更新泽西版本?还如何更新EclipseLink版本?他们的网站似乎只有版本2.6.0可用: http://www.eclipse.org/eclipselink /#下载



我假设所有这些都可以通过eclipse本身完成?



所有帮助感谢!



编辑1:看起来像eclipselink 2.6.1已经在2015年10月15日发布,你可以在这里看到: http://www.eclipse.org/eclipselink/releases/



然而,正如你可以看到的,它似乎并没有被纳入eclipse的帮助 - >更新软件: http://download.eclipse.org/rt/eclipselink/updates/



这是非常讨厌的。



我正在建立我的REST网站,没有PUT或POST会因为这个错误而工作。有没有人知道如何获得2.6.1的工作?



我正在使用一个Maven球衣 - quickstart-webapp项目。



这个bug是一个皇室痛苦的脸。



编辑2:今天我有一个黑客工作。当我在程序上检查在运行时如何使用eclipselink的版本,它告诉我是2.6.1版本,即使错误仍然存​​在:

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

在相关问题(如何查找我的Eclipse Project的EclipseLink的哪个版本?)我发现如何找到glassfish用于日食的实际jar文件。他们在glassfish / modules目录中。在org.eclipse.persistence.core.jar文件中将有一个readme.html,它告诉你glassfish正在使用的eclipselink的版本。对我而言是2.6。



我手动更新了org.eclipse.persistence.core.jar和最新版本的org.eclipse.persistence.moxy.jar文件从maven网站。虽然这是非常棘手的,因为我不知道这样做还有什么影响,它会解决这个问题。如果我找到正确的方法,我将在下面为所有和各种各样的人写一个答案。

解决方案

问题通过更新glassfish正在使用的eclipselink的版本来解决。 Eclipse更新它的版本,但glassfish需要它自己的更新。在此答案中给出了需要放置在glassfish / modules目录中的jar文件列表:如何在GlashFish 4.0中更改EclipseLink?


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.

解决方案

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?

这篇关于在Eclipse和Glassfish中使用JAX-RS时找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆