jersey 2.7 issue while running it on apache tomcat 7.0

点点圈 提交于 2019-11-30 12:33:30
Akalanka

At last solved. Please check below jar files. It is disgusting to use this number of jar files to implement REST services. May be restlet or easy rest is better than jersey.

hk2-api-2.2.0.jar
hk2-locator-2.2.0.jar
hk2-utils-2.2.0.jar
javassist-3.18.1-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.2.0.jar
javax.ws.rs-api-2.0.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet.jar
jersey-container-servlet-core.jar
jersey-guava-2.8.jar
jersey-server.jar,
validation-api-1.1.0.Final.jar

Hope someone may find this useful. The above is known working with jersey version 2.8

I believe you are missing Google guava dependency jars missing. Try to download and add them to your classpath.

Was able to get the basic REST webservice working for Jersey 2.8.Do let me know if there is a better way to do this.

pom.xml:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.8</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.8</version>
    </dependency>
</dependencies>

web.xml:

<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>
        org.glassfish.jersey.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>jersey.config.servlet.provider.webapp</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Greeting.java:

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

@Path("greeting")
public class Greeting {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String greeting(){
    return "Welcome!!";
}
}

You need to add the following jar files to your web-inf/lib folder, also you need to configure build path -- Right click your project--Build path -- configure build path -- libraries -- add external jars (add all the below jar files). And restart server

jersey-guava-2.x.jar is the jar you may be missing on your runtime setup - you may want to package all the extension jars as found under jaxrs-ri/ext from the Jersey JAX-RS 2.0 RI bundle - see https://jersey.java.net/download.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!