泽西服务与Tomcat和Eclipse [英] Jersey Services with Tomcat and Eclipse
问题描述
我正在使用Jersey 2.0开发休息服务(我从 http://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.5/jaxrs-ri-2.5.zip )我正在使用Tomcat 7.0.47。我从Eclipse运行Tomcat,我的机器是Mac。
I'm developing a rest service with Jersey 2.0 (I downloaded from http://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.5/jaxrs-ri-2.5.zip) and I'm using Tomcat 7.0.47. I run Tomcat from Eclipse and my machine is a Mac.
我使用Eclipse工具来生成WAR并部署服务。
I'm using the Eclipse tool to generate a WAR and to deploy the service.
这是我的web.xml:
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyServices</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.service.services.Services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
除了 javax之外,我将所有Jersey jar包含到WEB-INF / lib中。 servlet-api-3.0.1.jar
它是进入Apache / lib
当我在Tomcat中部署时,它显示了一个非常奇怪的错误:
I include all Jersey jars into WEB-INF/lib, except javax.servlet-api-3.0.1.jar
that it is into Apache/lib
When I deploy in Tomcat, it shows a very strange error caused by:
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.ClientConfig
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 70 more
推荐答案
我的解决方案:
- 将您从泽西岛下载的所有库添加到Tomcat / lib中,
包含在Jersey.zip $ b的 - 添加到我的项目的Web-Inf / lib中只有位于泽西zip文件
/ lib
文件夹下的库 - 添加到我的项目的Web-Inf / lib
javax.ws.rs-api-2.jar
,您可以在/ api
文件夹中找到
/ ext
文件夹中$ b - Add into Tomcat/lib all libraries that you download from Jersey and
are including into
/ext
folder of the Jersey .zip - Add into Web-Inf/lib of my project only libraries that are under
/lib
folder of the Jersey zip file - Add into Web-Inf/lib of my project
javax.ws.rs-api-2.jar
that you can find in/api
folder of Jersey
With this, I don't have problems to run Tomcat with Jersey.
这是我的web.xml for Jersey 2.0
And this is my web.xml for Jersey 2.0
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyRESTServices</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myservice.services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
其中 com.myservice.services
是包裹我有我的服务
Where com.myservice.services
is the package where I have my services
感谢您的意见!!
这篇关于泽西服务与Tomcat和Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!