泽西岛java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer [英] Jersey java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

查看:91
本文介绍了泽西岛java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jersey库在Tomcat和Eclipse中进行Web服务. 这是我的服务类别:

I'm trying to make a web-service with Tomcat and Eclipse using jersey library. This is my service class:

package com.gontuseries.university;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;


@Path("/university")
public class UniversityRestWs {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String getHtmlUniversityInfo(){
        return "<html><body>test</body></html>";
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTextUniversityInfo(){
        return "test";
    }
}

这是文件web.xml

And this is file web.xml

 <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.gontuseries.university</param-value>
 </init-param>
 </servlet>
 <servlet-mapping>
 <servlet-name>Jersey REST Service</servlet-name>
 <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>

当我测试服务时,我得到java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer 我从 https://jersey.java.net/download.html

When i test my service i get java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer I downloaded jersey from https://jersey.java.net/download.html

有人可以帮助我吗? 谢谢

Can someone help me? Thanks

推荐答案

对我来说,问题是服务器在lib文件夹中没有jar. 确保它可以访问以下项中的所有依赖项: 项目->属性->开发程序集->添加-> Java构建路径条目.

For me the problem was that the server had no jars in the lib folder. Make sure it has access to all dependencies in: project -> properties -> development assembly -> add -> java build path entries.

这篇关于泽西岛java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆