Jersey Services with Tomcat and Eclipse

前端 未结 4 1712
傲寒
傲寒 2020-12-10 09:24

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 To

相关标签:
4条回答
  • 2020-12-10 09:47

    My solution:

    1. Add into Tomcat/lib all libraries that you download from Jersey and are including into /ext folder of the Jersey .zip
    2. Add into Web-Inf/lib of my project only libraries that are under /lib folder of the Jersey zip file
    3. 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.

    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>
    

    Where com.myservice.services is the package where I have my services

    Thanks for your comments!!

    0 讨论(0)
  • 2020-12-10 09:51

    Adding Jersey to an Eclipse project without maven is simple: Click properties for the project, go to the Java Build Path. Click on the Add Library on the left, select user library. After you click next you will see "user libraries" in the upper right. Click that. Click new. Add a name: jaxrs-ri-2.5 for example. Click add external jars, and add the jars in the api, lib and ext folders. You're done. This will probably also include them in any war file you make with eclipse.

    Worked for me.

    0 讨论(0)
  • 2020-12-10 09:53

    Go with jdk1.7.0_04 and install apache-tomcat-7.0.55 and set the environment variable for this setting and set eclipse for same for compiling building and runtime. then everything will be OK for Jax-RS-2.1

    0 讨论(0)
  • 2020-12-10 09:54

    It works for me on a PC. Did you make the eclipse project a maven project? If you do that then you can use org.glassfish.jersey.bundles jaxrs-ri version 2.5 (or whichever) as a dependency in your pom and then when you do run->maven-install from eclipse it will build a war file with all the necessary dependencies in it.

    0 讨论(0)
提交回复
热议问题