3

我在我的开发系统上使用 GlassFish 4.0 R89,使用 JAX-RS。简单的调用工作,所以我可以得到一个序列化的对象,用 XML 表示。我必须将它安装在一个也将参与编码过程的人的机器上,我也在我的笔记本上尝试过 - 我得到了相同的结果 - 为类 JsonStructureBodyReader 抛出了 NoClassDefFoundError (虽然我'我什至没有使用 JSON,试过了,服务器肯定会返回带有内容类型正确标头的 XML)。

我以为我可能错误地导入了一个项目,但是在比较了工作版本和非工作版本中的文件之后,我意识到似乎没有可能对此负责的差异(项目更多或两台机器上的相等)。

我想也许GF版本有问题,所以我检查了一下,但两个安装都是R89。但是: GFs modules/ 目录中的 jars 似乎有所不同,尤其是在进行二进制比较时。

有没有人遇到过这个问题?

这是完整的堆栈跟踪:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/glassfish/json/jaxrs/JsonStructureBodyReader
at org.glassfish.jersey.jsonp.JsonProcessingFeature.configure(JsonProcessingFeature.java:69)
at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:617)
at org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:558)
at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:361)
at org.glassfish.jersey.client.ClientConfig$State.access$000(ClientConfig.java:84)
at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:116)
at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:113)
at org.glassfish.jersey.internal.util.collection.Values$LazyValue.get(Values.java:275)
at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:667)
at org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:169)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:644)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:375)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:275)
at my.application.client.webservice.data.IssueClient.getIssues(IssueClient.java:50)
at my.application.client.webservice.data.IssueClient.getIssues(IssueClient.java:30)
at my.application.client.modules.issuetracker.IssueTracker.getTableData(IssueTracker.java:182)
at my.application.client.modules.issuetracker.IssueTracker.drawComponents(IssueTracker.java:80)
at my.application.client.modules.issuetracker.IssueTracker.<init>(IssueTracker.java:59)
at my.application.client.actions.ShowIssueTrackerAction.fire(ShowIssueTrackerAction.java:37)
at my.application.client.gui.PVAppMenu$2.actionPerformed(PVAppMenu.java:49)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
4

4 回答 4

7

如果您不使用 JSON(JSON 处理库),那么您应该jersey-media-json-processing从客户端的类路径中删除模块(这似乎在 GF 之外)。该模块依赖于jsonp-jaxrs.jar(+ javax.json.jar, javax.json-api.jar) ,其中包含JsonStructureBodyReader. 问题是,每当jersey-media-json-processing模块位于类路径上时,Jersey 都会尝试通过自动发现机制注册 JSON 处理提供程序。这意味着在缺少依赖项的情况下,会遇到与您类似的异常。

于 2013-08-20T11:38:48.120 回答
3

只需从 Eclipse 的构建路径中删除 glassfish 库。然后添加外部 jar,并添加 glassfish4 目录中以下文件夹中的所有 jar。

  1. C:\glassfish4\glassfish\modules
  2. C:\glassfish4\glassfish\modules\endorsed
  3. C:\glassfish4\mq\lib

这是我用来使用 JAX RS 编写 REST 客户端的客户端代码

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;


public class test {

    public static void main(String[] args) {

        Client client = ClientBuilder.newClient();
        String name = client.target("http://localhost:9999/MyResourceRestfulService/myresources/myresource")
          .request(MediaType.TEXT_PLAIN)
          .get(String.class);

        System.out.println(name);
    }

}
于 2014-01-29T05:09:37.180 回答
1

如果您使用 Glassfish 4.x 作为服务器及其库。你必须添加 javax.son.jar jsonp-jaxrs.jar

两个库都位于 \glassfish\modules

于 2015-04-22T06:41:40.217 回答
0

如果您使用带有 MAVEN 的 JUNIT 测试,只需添加

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jsonp-jaxrs</artifactId>
    <version>1.0</version>
    <scope>test</scope>
</dependency>

到你的 pom.xml

于 2016-04-15T08:55:21.503 回答