我正在设置我的Jersey Web服务,但无法运行它,Apache Tomcat 8.5出错了。有关简单代码,我的库和错误,请参见下面的详细信息。
我创建了一个动态Web项目...
我添加了我的Jersey文件...(我错过了吗?)
javax.ws.rs-api.2.0.1.jar
jersey-client.jar
jersey-common.jar
jersey-contaner-servlet.jar
jersey-container-servlet.jar
jersey-media-jaxb.jar
jersey-server.jar
我的Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<servlet>
<servlet-name>myApi</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<!-- The package where your resource classes are -->
<param-value>WS</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>testApi</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
我的Java课
package ws;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
@Path("test")
public class Connect {
@GET
@Path("test")
@Produces(MediaType.TEXT_PLAIN)
public String hello(){
return "hello world";
}
}
我的错误之前弹出说无法启动Apachev8.5
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ThisApi]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ThisApi]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
... 6 more
Caused by: java.lang.NoClassDefFoundError: jersey/repackaged/com/google/common/base/Function
at org.glassfish.jersey.internal.ServiceFinder.<clinit>(ServiceFinder.java:165)
at org.glassfish.jersey.servlet.internal.ServletContainerProviderFactory.getAllServletContainerProviders(ServletContainerProviderFactory.java:66)
at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:134)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: jersey.repackaged.com.google.common.base.Function
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 11 more
最佳答案
您缺少jersey-guava.jar
,其中应该包含Google Guava类的软件包重新打包的版本,包括Function
。 Jersey重新包装了所需的确切版本,因此您仍可以从其原始包装结构中使用您喜欢的Guava版本。请参见https://stackoverflow.com/a/22069399/27905。
https://mvnrepository.com/artifact/org.glassfish.jersey.bundles.repackaged/jersey-guava