java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer [英] java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
问题描述
我正在尝试使用 Jersey + Google 应用引擎构建一个简单的 hello world 应用程序,为期两天.对于简单的 AppEngine 项目,我遵循了这些教程,两者都运行良好https://developers.google.com/appengine/docs/java/gettingstarted/creatinghttps://developers.google.com/appengine/docs/java/webtoolsplatform
I am trying to build a simple hello world application for two days using Jersey + Google app engine. For simple AppEngine project I followed these tutorials and both works just fine https://developers.google.com/appengine/docs/java/gettingstarted/creating https://developers.google.com/appengine/docs/java/webtoolsplatform
但现在我正在尝试添加 Jersey 并遵循本教程 http://www.vogella.com/articles/REST/article.html.
But now I am trying to add Jersey and following this tutorial http://www.vogella.com/articles/REST/article.html.
但是服务器一直给我
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
当我在 web.xml 中添加这些行时:
when I add these lines in 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TestServer</display-name>
<servlet>
<servlet-name>Jersey REST Service</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>com.test.myproject</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
我已从 此处JAX-RS 2.1 RI 包> 并按照教程中的说明在 WEB-INF/lib
文件夹中添加了所有 jar 文件.即使两天后也没有任何效果.我在谷歌上搜索了几次,显然使用 Maven 的人已经以某种方式解决了它,但我没有使用 Maven,编写该教程的人也没有使用.
I have downloaded Jersey JAX-RS 2.1 RI bundle
from here and have added all jar files in WEB-INF/lib
folder as described in tutorial. And even after two days nothing is working. I have searched several times on Google and apparently people who are using Maven have solved it somehow but I am not using Maven neither did the guy who wrote that tutorial.
只是为了检查在导入的 Jersey jars
中是否存在 com.sun.jersey.spi.container.servlet.ServletContainer
我试图在Java 并让智能感知完成名称,但在 com.sun.je
之后我无法获得任何智能感知,所以我最后的猜测是在最新的 Jersey 中进行了一些包重新排列build 和 jersey
不再位于 com.sun
中.我已经筋疲力尽了,如果能得到任何帮助,我将不胜感激.
Just to check if even com.sun.jersey.spi.container.servlet.ServletContainer
exists in imported Jersey jars
I tried to just write this fully qualified name in Java and let the intellisense finish names but I couldn't get any intellisense after com.sun.je
so my last guess is that there have been some package rearrangement in latest Jersey build and jersey
is no longer inside com.sun
. I am exhausted and I would appreciate any kind of help.
推荐答案
您已下载 Jersey 2(JAX-RS 2 的 RI).您所指的教程使用 Jersey 1. 从 (这里),对你来说应该足够了.
You have downloaded Jersey 2 (which RI of JAX-RS 2). The tutorial you're referring to uses Jersey 1. Download Jersey 1.17.1 from (here), should be sufficient for you.
Jersey 1 使用 com.sun.jersey
,而 Jersey 2 使用 org.glassfish.jersey
因此例外.
Jersey 1 uses com.sun.jersey
, and Jersey 2 uses org.glassfish.jersey
hence the exception.
另请注意,以 com.sun.jersey
开头的 init-param
也不会被 Jersey 2 识别.
Also note that also init-param
starting with com.sun.jersey
won't be recognized by Jersey 2.
在泽西岛 2 注册资源和提供者 包含有关如何在 Jersey 2 中注册类/实例的其他信息.
Registering Resources and Providers in Jersey 2 contains additional info on how to register classes/instances in Jersey 2.
这篇关于java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!