eclipse - Create a web service with Tomcat 5.5.30 and Jersey -


i strugging make hello world jersey web service on tomcat 5.5.30. using eclipse galileo. not using maven.

  • created dynamic web module in version 2.4
  • created new package com.company.webservice in java resources: src folder of eclipse project
  • added following libraries project, jaxrs-ri-2.19:

    • javax.ws.rs-api-2.0.1.jar
    • jersey-client.jar
    • jersey-common.jar
    • jersey-container-servlet.jar
    • jersey-container-servlet-core.jar
    • jersey-media-jaxb.jar
    • jersey-server.jar
    • aopalliance-repackaged-2.4.0-b25.jar
    • asm-debug-all-5.0.3.jar
    • hk2-api-2.4.0-b25.jar
    • hk2-locator-2.4.0-b25.jar
    • hk2-utils-2.4.0-b25.jar
    • javassist-3.18.1-ga.jar
    • javax.annotation-api-1.2.jar
    • javax.inject-2.4.0-b25.jar
    • javax.servlet-api-3.0.1.jar
    • jaxb-api-2.2.7.jar
    • jersey-guava-2.19.jar
    • org.osgi.core-4.2.0.jar
    • osgi-resource-locator-1.0.1.jar
    • persistence-api-1.0.jar
    • validation-api-1.1.0.final.jar

here 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="2.4">  <display-name>ws_server</display-name>    <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>   <servlet>    <servlet-name>helloservice</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.company.webservice</param-value>    </init-param>     <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>helloservice</servlet-name>    <url-pattern>/rest/*</url-pattern>  </servlet-mapping> </web-app> 

i added following helloservice.java in package created:

package com.company.webservice;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.pathparam; import javax.ws.rs.core.response;   @path("/hello") public class helloservice {      @get     @path("/{param}")     public response getmsg(@pathparam("param")     string msg) {          string output = "jersey answers : " + msg;          return response.status(200).entity(output).build();      } } 

but when start tomcat server following error:

4 août 2015 09:31:29 org.apache.catalina.core.applicationcontext log info: la servlet helloservice est marqué comme indisponible 4 août 2015 09:31:29 org.apache.catalina.core.applicationcontext log grave: error loading webappclassloader   delegate: false   repositories:     /web-inf/classes/ ----------> parent classloader: org.apache.catalina.loader.standardclassloader@1522de2  org.glassfish.jersey.servlet.servletcontainer java.lang.classnotfoundexception: org.glassfish.jersey.servlet.servletcontainer     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1436)     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1282)     @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1068)     @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:966)     @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:3996)     @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4266)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardhost.start(standardhost.java:736)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardengine.start(standardengine.java:443)     @ org.apache.catalina.core.standardservice.start(standardservice.java:448)     @ org.apache.catalina.core.standardserver.start(standardserver.java:700)     @ org.apache.catalina.startup.catalina.start(catalina.java:552)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:585)     @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:295)     @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:433) 4 août 2015 09:31:29 org.apache.catalina.core.standardcontext loadonstartup grave: la servlet /serveurws généré une exception "load()" java.lang.classnotfoundexception: org.glassfish.jersey.servlet.servletcontainer     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1436)     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1282)     @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1068)     @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:966)     @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:3996)     @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4266)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardhost.start(standardhost.java:736)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardengine.start(standardengine.java:443)     @ org.apache.catalina.core.standardservice.start(standardservice.java:448)     @ org.apache.catalina.core.standardserver.start(standardserver.java:700)     @ org.apache.catalina.startup.catalina.start(catalina.java:552)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:585)     @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:295)     @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:433) 

update

if deploy jars in apache-tomcat-5.5.30\webapps\serveurws\web-inf\lib folder (thank peeskillet this), have error, looks version error:

5 août 2015 14:10:41 org.apache.catalina.loader.webappclassloader validatejarfile info: validatejarfile(f:\java\apache-tomcat-5.5.30\webapps\serveurws\web-inf\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. see servlet spec 2.3, section 9.7.2. offending class: javax/servlet/servlet.class java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:585)     @ org.apache.catalina.startup.bootstrap.start(bootstrap.java:295)     @ org.apache.catalina.startup.bootstrap.main(bootstrap.java:433) caused by: java.lang.unsupportedclassversionerror: bad version number in .class file (unable load class org.glassfish.jersey.servlet.servletcontainer)     @ org.apache.catalina.loader.webappclassloader.findclassinternal(webappclassloader.java:1962)     @ org.apache.catalina.loader.webappclassloader.findclass(webappclassloader.java:931)     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1403)     @ org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1282)     @ org.apache.catalina.core.standardwrapper.loadservlet(standardwrapper.java:1068)     @ org.apache.catalina.core.standardwrapper.load(standardwrapper.java:966)     @ org.apache.catalina.core.standardcontext.loadonstartup(standardcontext.java:3996)     @ org.apache.catalina.core.standardcontext.start(standardcontext.java:4266)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardhost.start(standardhost.java:736)     @ org.apache.catalina.core.containerbase.start(containerbase.java:1014)     @ org.apache.catalina.core.standardengine.start(standardengine.java:443)     @ org.apache.catalina.core.standardservice.start(standardservice.java:448)     @ org.apache.catalina.core.standardserver.start(standardserver.java:700)     @ org.apache.catalina.startup.catalina.start(catalina.java:552)     ... 6 more 

so had remove previous libraries , use these libraries:

jersey-bundle-1.1.5.1.jar asm-3.1.jar jsr311-api-1.1.1.jar 

change web.xml into:

<?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="2.4">  <display-name>serveurws2</display-name>    <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>   <servlet>    <servlet-name>helloservice</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.company.webservice</param-value>    </init-param>    <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>helloservice</servlet-name>    <url-pattern>/rest/*</url-pattern>  </servlet-mapping>  </web-app> 

and copy libraries in web-inf\lib folder of application in webapps folder of tomcat server.

big go peeskillet


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -