2016-01-18 97 views
2

試圖從JAXB上自由配置文件服務器對象上返回Json而沒有成功。 XML完美無缺。在依賴關係樹中看不到任何奇怪的東西。Jersey Liberty Profile上的JAXB json

什麼可能是錯的?

Caused by: java.lang.VerifyError: JVMVRFY027 receiver is incompatible with declaring class; class=org/eclipse/persistence/jaxb/compiler/Generator, method=generateSchemaFiles(Ljava/lang/String;Ljava/util/Map;)Ljava/util/Map;, pc=89 
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1099) 
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:189) 
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:165) 
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:152) 
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:112) 
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:102) 
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.getJAXBContext(MOXyJsonProvider.java:318) 
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.getJAXBContext(MOXyJsonProvider.java:337) 
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.isWriteable(MOXyJsonProvider.java:580) 
    at org.glassfish.jersey.moxy.json.internal.ConfigurableMoxyJsonProvider.isWriteable(ConfigurableMoxyJsonProvider.java:201) 
    at org.glassfish.jersey.message.internal.MessageBodyFactory.isWriteable(MessageBodyFactory.java:1160) 
    at org.glassfish.jersey.message.WriterModel.isWriteable(WriterModel.java:86) 
    at org.glassfish.jersey.message.internal.MessageBodyFactory._getMessageBodyWriter(MessageBodyFactory.java:798) 
    at org.glassfish.jersey.message.internal.MessageBodyFactory.getMessageBodyWriter(MessageBodyFactory.java:756) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:241) 
    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:711) 
    at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444) 
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434) 
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329) 

的web.xml

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 

    <servlet> 
     <servlet-name>Service</servlet-name> 
     <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>jersey.config.server.provider.packages</param-name> 
      <param-value>com.my.services.agent</param-value> 
     </init-param> 

     <init-param> 
      <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name> 
      <param-value>true</param-value> 
     </init-param> 

     <init-param> 
      <!-- With WebSphere, to see the service response in case of errors instead of the 
       Websphere default error page, Jersey has to be configured in this way. 
      https://java.net/jira/browse/JERSEY-2521 --> 
      <param-name>jersey.config.server.response.setStatusOverSendError</param-name> 
      <param-value>true</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Service</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

@XmlRootElement 
public class TestObj { 
    public String name; 
    public int age; 

    public TestObj() { 
    } // JAXB needs this 

    public TestObj(String name) { 
     this.name = name; 
    } 
} 

TestResource.java

@GET 
@Path("/ex2") 
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.TEXT_HTML}) 
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML, MediaType.TEXT_HTML}) 
public TestObj ex2() { 
    return new TestObj("test"); 
} 

的pom.xml

<jersey.version>2.22.1</jersey.version> 
... 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.1.0</version> 
</dependency> 
<dependency> 
    <groupId>org.glassfish.jersey.containers</groupId> 
    <artifactId>jersey-container-servlet</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.glassfish.jersey.media</groupId> 
    <artifactId>jersey-media-moxy</artifactId> 
</dependency> 

<dependencyManagement> 
<dependencies> 
    <dependency> 
    <groupId>org.glassfish.jersey</groupId> 
    <artifactId>jersey-bom</artifactId> 
    <version>${jersey.version}</version> 
    <type>pom</type> 
    <scope>import</scope> 
    </dependency> 
</dependencies> 
</dependencyManagement> 

回答

1

此固定用下列:

<dependency> 
    <groupId>org.glassfish.jersey.containers</groupId> 
    <artifactId>jersey-container-servlet</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.glassfish.jersey.media</groupId> 
    <artifactId>jersey-media-json-jackson</artifactId> 
    <version>2.22.1</version> 
</dependency> 
相關問題