ClassNotFoundException on com.sun.jersey.spi.container.servlet.ServletContainer

笑着哭i 提交于 2019-12-10 15:16:08

问题


I am migrating project from jBoss-eap-5.1 to jboss-eap-6.0. I have defined jersey jars in the modules directory of jboss as follows:

com
|_jersey
  |_jersey-core
  |_jersey-client
  |_jersey-server
  |_jersey-servlet

In my project .pom file i defined the jars as follows:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.10</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>${jersey-version}</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey-version}</version>
    <scope>test</scope>
</dependency>

However, when I try to deploy, I get the following error on ServletContainer class:

13:03:29,908 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.subunit."ApiEar-2.0.0-SNAPSHOT.ear"."ApiService-2.
0.0-SNAPSHOT.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."ApiEar-2.0.0-SNAPSHOT.ear"."ApiService-2.0.0-SNAPSHOT.war".POST_MODULE
: JBAS018733: Failed to process phase POST_MODULE of subdeployment "ApiService-2.0.0-SNAPSHOT.war" of deployment "ApiEar-2.0.0-SNAPSHOT.ear"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:123) [jboss-as-server-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_32-ea]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_32-ea]
        at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32-ea]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Modu
le "deployment.ApiEar-2.0.0-SNAPSHOT.ear.ApiService-2.0.0-SNAPSHOT.war:main" from Service Module Loader]
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:295)
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scanWebDeployment(JaxrsScanningProcessor.java:160)
        at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:109)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:116) [jboss-as-server-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

        ... 5 more

Initially, I was getting this error when I did not define jersey-servlet, but I did some searching, and presumably, jersey-servlet.jar is the one that contains that class. However, that did solve the error.


回答1:


I have solved the issue by adding this dependencies into my manifest.mf file. In my .pom file I added the build plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <configuration>
         <archive>
             <manifestEntries>
                  <Dependencies>com.jersey.jersey-server,com.jersey.jersey-client,com.jersey.jersey-json</Dependencies>
             </manifestEntries>
         </archive>
    </configuration>
</plugin>

that added references to the needed .jar files in my manifest file




回答2:


Not an answer, but I believe this was implemented in jersey in version 10. That is when big overhaul of library happened



来源:https://stackoverflow.com/questions/15031697/classnotfoundexception-on-com-sun-jersey-spi-container-servlet-servletcontainer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!