Java Web应用程序无法使用Jersey 2.26在Tomcat 8.5或9上启动

时间:2018-08-18 02:53:41

标签: java rest jersey tomcat8 tomcat9

我正在尝试使用使用Maven构建的Jersey 2.26将简单的Java(1.8)Web应用程序部署到Tomcat 9(也在8.5上进行了尝试)。在构建但部署到Tomcat时,我没有看到任何错误,该应用程序无法启动。

enter image description here

我指的是https://jersey.github.io/documentation/latest/deployment.html#deployment.servlet.3

中列出的选项

Tomcat logs / catalina.out中的错误

window.gm_authFailure = function() { alert("Auth failed!"); };

17-Aug-2018 21:46:06.062 SEVERE [http-nio-8080-exec-39] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/Users/konathal/Software/apache-tomcat-9.0.10/webapps/jaq-stack-webapp.war] java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [

pom.xml

Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/core/Application
    at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.addServletWithDefaultConfiguration(JerseyServletContainerInitializer.java:240)

web.xml

 <dependency>
   <groupId>org.glassfish.jersey.containers</groupId>
   <artifactId>jersey-container-servlet</artifactId>
   <version>2.26</version>
 </dependency>
 <dependency>
   <groupId>org.glassfish.jersey.core</groupId>
   <artifactId>jersey-server</artifactId>
   <version>2.26</version>
 </dependency>
 <dependency>
   <groupId>org.glassfish.jersey.inject</groupId>
   <artifactId>jersey-hk2</artifactId>
   <version>2.26</version>
 </dependency>

Servlet类

<servlet>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
  <servlet-name>javax.ws.rs.core.Application</servlet-name>
  <url-pattern>/service/*</url-pattern>
</servlet-mapping>

我想念什么?

2 个答案:

答案 0 :(得分:0)

看起来像一个丢失的罐子。实际上,关于javax/ws/rs/core/Application找不到的事实,堆栈跟踪消息非常清楚。

将此依赖项添加到您的pom.xml清理并重建项目中,我想您应该可以。

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1</version>
</dependency>

答案 1 :(得分:0)

就像@Aris_Kortex提到的问题是缺少

解决方案是从pom.xml中的maven依赖项中删除<scope>provided</scope>

之前我pom.xml中的依赖项

<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>javax.ws.rs-api</artifactId>
  <version>2.1</version>
  <scope>provided</scope>
</dependency>

更正的依存关系

<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>javax.ws.rs-api</artifactId>
  <version>2.1</version>
</dependency>

Tomcat不提供jar,必须由应用程序显式添加。