生成 JSON 时出现 Glassfish 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33722764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Glassfish error when producing JSON
提问by Alejandro M López Cerezo
I developed an Android app and now I'm starting with its external DB and its server, the communication is performed by RESTful web services.
我开发了一个 Android 应用程序,现在我从它的外部数据库和它的服务器开始,通信由 RESTful Web 服务执行。
This Android aplication just produces and consumes info in JSON, so in my web services facades I just want to erase any mention to XML in the CRUD methods, (automatically generated by NetBeans).
此 Android 应用程序仅生成和使用 JSON 格式的信息,因此在我的 Web 服务外观中,我只想删除 CRUD 方法(由 NetBeans 自动生成)中对 XML 的任何提及。
I mean, from this:
我的意思是,从这个:
@GET
@Override
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Counselor> findAll() {
return super.findAll();
}
To this (without the MediaType.APPLICATION_XML):
为此(没有 MediaType.APPLICATION_XML):
@GET
@Override
@Produces(MediaType.APPLICATION_JSON)
public List<Counselor> findAll() {
return super.findAll();
}
The thing is that when I deploy these changes in my GlassFish Server (4.1.1) and do some tests with my browser (just want to see my DB data) I get an error with this stacktrace:
问题是,当我在 GlassFish Server (4.1.1) 中部署这些更改并使用我的浏览器进行一些测试(只想查看我的数据库数据)时,我收到此堆栈跟踪错误:
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
at org.eclipse.persistence.jaxb.JAXBBeanValidator.isConstrainedObject(JAXBBeanValidator.java:257)
at org.eclipse.persistence.jaxb.JAXBBeanValidator.shouldValidate(JAXBBeanValidator.java:208)
at org.eclipse.persistence.jaxb.JAXBMarshaller.validateAndTransformIfNeeded(JAXBMarshaller.java:587)
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:481)
at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:949)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:683)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:424)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:414)
at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:312)
at org.glassfish.jersey.internal.Errors.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Any idea about this?
对此有什么想法吗?
I hope I explain myself...thanks in advance!!
我希望我解释一下...提前致谢!!
回答by hannes ach
It's a bug in Glassfish 4.1.1 https://java.net/jira/browse/JERSEY-2888
这是 Glassfish 4.1.1 https://java.net/jira/browse/JERSEY-2888 中的一个错误
I was able to fix it in a dirty way:
我能够以一种肮脏的方式修复它:
In glassfish/modules/org.eclipse.persistence.moxy.jar fix META-INF/MANIFEST.MF Just append the following to Import-Package:
在 glassfish/modules/org.eclipse.persistence.moxy.jar 中修复 META-INF/MANIFEST.MF 只需将以下内容附加到 Import-Package:
,org.xml.sax.helpers,javax.xml.parsers;resolution:=optional,javax.naming;resolution:=optional
so it looks like after:
所以它看起来像:


and restart GF
并重启GF
btw: you can easy edit jars in terminal with
顺便说一句:您可以轻松地在终端中编辑 jars
emacs org.eclipse.persistence.moxy.jar
回答by Leon
Hyman's answer is really helpful.
It pinpoints the problem and was useful when there was no patch.
But I suggest instead of editing the jar, since the bug is corrected in 2.6.1,
to download itat :
org.eclipse.persistence.moxy-2.6.1 from MVNRepository
Hyman的回答真的很有帮助。
它可以查明问题,并且在没有补丁时很有用。
但我建议,而不是编辑的罐子,因为bug在2.6.1修正,以下载它在:
org.eclipse.persistence.moxy-2.6.1从MVNRepository
OR get the latest version from MVNRepository: https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
或从 MVNRepository 获取最新版本:https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
and replace it.
Don't forget to close and reopen you IDE.
并更换它。
不要忘记关闭并重新打开您的 IDE。

