本文介绍了使用Eclipse,JBoss 7.1.1和Jersey 1获取ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个宁静的Web服务,但出现此错误:

I am developing a restful Web Service, but i'm getting this error:

我知道有很多这类问题.我已经检查了他们并尝试了他们的解决方案,但是我遇到的错误仍然存​​在.

I know there are many topics with this kind of problem. I already checked them out and tried their solutions, but the error i am getting remains.

这是我的 pom.xml :

Here's my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi`enter code here`="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-jaxrs-server</artifactId>
  <packaging>jar</packaging>
  <name>swagger-jaxrs-server</name>
  <version>1.0.0</version>
  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
         </executions>
       </plugin>
       <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jetty-version}</version>
        <configuration>
          <webApp>
            <contextPath>/</contextPath>
          </webApp>
          <webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
          <stopPort>8079</stopPort>
          <stopKey>stopit</stopKey>
          <httpConnector>
            <port>8080</port>
            <idleTimeout>60000</idleTimeout>
          </httpConnector>
        </configuration>
        <executions>
          <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
            <configuration>
              <scanIntervalSeconds>0</scanIntervalSeconds>
              <daemon>true</daemon>
            </configuration>
          </execution>
          <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.9.1</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/gen/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-jersey-jaxrs</artifactId>
  <version>1.5.0</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>${slf4j-version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-core</artifactId>
  <version>${jersey-version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-json</artifactId>
  <version>${jersey-version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-servlet</artifactId>
  <version>${jersey-version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey.contribs</groupId>
  <artifactId>jersey-multipart</artifactId>
  <version>${jersey-version}</version>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-server</artifactId>
  <version>${jersey-version}</version>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>${servlet-api-version}</version>
</dependency>

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit-version}</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-client</artifactId>
  <version>${jersey-version}</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.8.8</version>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <artifactId>junit</artifactId>
      <groupId>junit</groupId>
    </exclusion>
    <exclusion>
      <artifactId>snakeyaml</artifactId>
      <groupId>org.yaml</groupId>
    </exclusion>
    <exclusion>
      <artifactId>bsh</artifactId>
      <groupId>org.beanshell</groupId>
    </exclusion>
  </exclusions>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
       <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <properties>
    <swagger-core-version>1.5.8</swagger-core-version>
    <jetty-version>9.2.9.v20150224</jetty-version>
    <jersey-version>1.18.1</jersey-version>
    <slf4j-version>1.6.3</slf4j-version>
    <junit-version>4.8.1</junit-version>
    <servlet-api-version>2.5</servlet-api-version>
  </properties>
</project>

这是我的 web.xml :

here's my web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet>
        <servlet-name>jersey</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>io.swagger.jaxrs.json;io.swagger.jaxrs.listing;io.swagger.api</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

  <servlet>
        <servlet-name>Jersey2Config</servlet-name>
        <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
        <init-param>
            <param-name>api.version</param-name>
            <param-value>1.0.0</param-value>
        </init-param>
        <init-param>
            <param-name>swagger.api.basepath</param-name>
            <param-value>http://localhost:8080/api</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>

  <servlet-mapping>
        <servlet-name>jersey</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>

  <filter>
    <filter-name>ApiOriginFilter</filter-name>
    <filter-class>io.swagger.api.ApiOriginFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>ApiOriginFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

,这是完整堆栈跟踪:

and here's the Full Stack Trace:

21:53:11,253 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-    13) JBAS015876: Starting deployment of "VoiceAuthMiddlewareEAR.ear"
21:53:11,256 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015876: Starting deployment of "VoiceAuthMiddleware.war"
21:53:11,308 WARN  [org.jboss.modules] (MSC service thread 1-10) Failed to  define class io.swagger.api.ApiOriginFilter in Module  "deployment.VoiceAuthMiddlewareEAR.ear.VoiceAuthMiddleware.war:main" from  Service Module Loader: java.lang.UnsupportedClassVersionError:  io/swagger/api/ApiOriginFilter : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_79]
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_79]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_79]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73)
at org.jboss.modules.Module.loadModuleClass(Module.java:517)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_79]
at java.lang.Class.forName(Class.java:274) [rt.jar:1.7.0_79]
at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:63) [jboss-as-ee- 7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]

21:53:11,316 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-10) MSC00001: Failed to start service jboss.deployment.subunit."VoiceAuthMiddlewareEAR.ear"."VoiceAuthMiddleware.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."VoiceAuthMiddlewareEAR.ear"."VoiceAuthMiddleware.war".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "VoiceAuthMiddleware.war" of deployment "VoiceAuthMiddlewareEAR.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.VoiceAuthMiddlewareEAR.ear.VoiceAuthMiddleware.war:main" from Service Module Loader]
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:290)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scanWebDeployment(JaxrsScanningProcessor.java:155)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer from [Module "deployment.VoiceAuthMiddlewareEAR.ear.VoiceAuthMiddleware.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.checkDeclaredApplicationClassAsServlet(JaxrsScanningProcessor.java:288)
... 8 more

21:53:11,424 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "VoiceAuthMiddlewareEAR.ear" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"VoiceAuthMiddlewareEAR.ear\".\"VoiceAuthMiddleware.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"VoiceAuthMiddlewareEAR.ear\".\"VoiceAuthMiddleware.war\".POST_MODULE: Failed to process phase POST_MODULE of subdeployment \"VoiceAuthMiddleware.war\" of deployment \"VoiceAuthMiddlewareEAR.ear\""}}
21:53:11,433 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2)  JBAS015877: Stopped deployment VoiceAuthMiddleware.war in 8ms
21:53:11,435 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-14) JBAS015877: Stopped deployment VoiceAuthMiddlewareEAR.ear in 11ms
21:53:11,437 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
  service jboss.naming.context.java.module.VoiceAuthMiddlewareEAR.VoiceAuthMiddleware (missing) dependents: [service jboss.naming.context.java.module.VoiceAuthMiddlewareEAR.VoiceAuthMiddleware.ValidatorFactory, service jboss.naming.context.java.module.VoiceAuthMiddlewareEAR.VoiceAuthMiddleware.Validator]
JBAS014777:   Services which failed to start:      service jboss.deployment.subunit."VoiceAuthMiddlewareEAR.ear"."VoiceAuthMiddleware.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.subunit."VoiceAuthMiddlewareEAR.ear"."VoiceAuthMiddleware.war".POST_MODULE: Failed to process phase POST_MODULE of subdeployment "VoiceAuthMiddleware.war" of deployment "VoiceAuthMiddlewareEAR.ear"

21:53:11,442 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.subunit.\"VoiceAuthMiddlewareEAR.ear\".\"VoiceAuthMiddleware.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.subunit.\"VoiceAuthMiddlewareEAR.ear\".\"VoiceAuthMiddleware.war\".POST_MODULE: Failed to process phase POST_MODULE of subdeployment \"VoiceAuthMiddleware.war\" of deployment \"VoiceAuthMiddlewareEAR.ear\""}}}}

感谢任何帮助.

推荐答案

JBoss AS为什么在泽西岛拥有自己的其余JAX-RS实现/RESTEasy,因此您无需添加jboss-deployment-structure.xml文件,因为该文件旨在在类路径上加载额外的模块

Why Jersey, JBoss AS has his own rest JAX-RS implementation / RESTEasy, of this way you won't need add jboss-deployment-structure.xml file, because this file is intended to load extra modules on the classpath

这篇关于使用Eclipse,JBoss 7.1.1和Jersey 1获取ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:42