当前位置: 首页 > 知识库问答 >
问题:

使用Eclipse、JBoss 7.1.1和Jersey 1获取ClassNotFoundException

谢雅珺
2023-03-14

我正在开发restful Web服务,但遇到以下错误:

Java语言lang.ClassNotFoundException:com。太阳运动衫spi。容器servlet。ServletContainer服务容器

我知道这类问题有很多话题。我已经检查了它们并尝试了它们的解决方案,但我得到的错误仍然存在。

这是我的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>

这是我的网站。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>

下面是完整的堆栈跟踪:

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\""}}}}

感谢您的帮助。

共有1个答案

狄睿
2023-03-14

为什么Jersey、JBoss AS有自己的RESTJAX-RS实现/RESTEasy,这样您就不需要添加JBoss部署结构了。xml文件,因为此文件用于在类路径上加载额外模块

 类似资料:
  • 我的项目有问题。我们正在使用JBoss7.1.1,我们希望在4.1版中使用envers。版本4.1中的Envers需要版本4.1中的Hibernate。不幸的是,jboss 7.1.1包含较旧的Hibernate和Envers模块。 我有两个选择: 更改JBoss中的模块(放置新的环境 或: 在war中排除JBoss模块并使用WEB-INF/lib中的libs。我使用以下方法排除了模块: 我已经将

  • 我最近有一个非常烦人的问题不知从哪里冒出来。在启用EclEmma覆盖的情况下运行我的单元测试会导致从Eclipse弹出以下对话框窗口: 对于搜索引擎,其内容如下: 在此覆盖会话期间没有收集覆盖数据。 请不要从Eclipse手动终止Java进程。 我的项目中没有提供任何类的覆盖信息。不用说,我不会手动终止Java过程。为了尝试修复它,我重新导入了我的项目,升级了Java,重新安装了Emma,重新启动

  • 在Eclipse3.6中运行代码时,我在下面的语句中得到了一个。1: 我读过类似问题的帖子,并尝试过答案,但运气不佳,包括: 使用绝对路径 使用各种相对路径 将gif放入各种文件夹(src、bin、lib等) 创建等待灯。gif- 我当前的图像项目路径是LosOMeter- 有什么想法吗? 堆栈跟踪:

  • 我使用spring boot 1.4.3.RELEASE来创建web服务,然而,在用,id属性为null 能不能请你指点一下,有没有我遗漏的。

  • 问题内容: 我是angular.js的新手,在看似简单的任务上遇到了一些麻烦。 我需要从网站上的json文件中获取下面的json,然后将键(英语,西班牙语等)放入我的html文件中的标签标记中,然后加载其对应的值(0、1、3、2、1 )转换成html范围输入。 json文件包含: 加载json后产生的html应该如下所示: 最后,我想在表单上单击“保存”,并在json文件上在线更新相应键的值。 生

  • 我正在尝试使用Hibernate以便从MySQL数据库中获取数据。为了实现这样一个目标,我创造了: > Hibernate配置文件: