java - Restful webservices with jersey and tomcat error: 404 -


i'm working eclipse creating dynamic web project. i'm using tomcat 7 , i've included jar jersey, here jars:

aopalliance-repackaged-2.4.0-b31.jar asm-debug-all-5.0.4.jar hk2-api-2.4.0-b31.jar hk2-locator-2.4.0-b31.jar hk2-utils-2.4.0-b31.jar javassist-3.18.1-ga.jar javax.annotation-api-1.2.jar javax.inject-2.4.0-b31.jar javax.servlet-api-3.0.1.jar javax.ws.rs-api-2.0.1.jar jaxb-api-2.2.7.jar jersey-client.jar jersey-common.jar jersey-container-servlet-core.jar jersey-container-servlet.jar jersey-guava-2.21.jar jersey-media-jaxb.jar jersey-server.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 

my xml is:

<?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>restful jersey hello world</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>restful</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.lorenzo.rest</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <servlet-mapping>     <servlet-name>restful</servlet-name>     <url-pattern>/rest/*</url-pattern>   </servlet-mapping> </web-app> 

when running project trace this:

set 21, 2015 12:30:52 pm org.apache.tomcat.util.digester.setpropertiesrule begin avvertenza: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:restful' did not find matching property. set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: server version:        apache tomcat/7.0.64 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: server built:          aug 19 2015 17:18:06 utc set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: server number:         7.0.64.0 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: os name:               windows xp set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: os version:            5.1 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: architecture:          x86 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: java home:             c:\programmi\java\jdk1.8.0_60\jre set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: jvm version:           1.8.0_60-b27 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: jvm vendor:            oracle corporation set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: catalina_base:         c:\documents , settings\gcappella\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: catalina_home:         c:\programmi\apache software foundation\tomcat 7.0 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: command line argument: -dcatalina.base=c:\documents , settings\gcappella\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: command line argument: -dcatalina.home=c:\programmi\apache software foundation\tomcat 7.0 set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: command line argument: -dwtp.deploy=c:\documents , settings\gcappella\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: command line argument: -djava.endorsed.dirs=c:\programmi\apache software foundation\tomcat 7.0\endorsed set 21, 2015 12:30:52 pm org.apache.catalina.startup.versionloggerlistener log informazioni: command line argument: -dfile.encoding=cp1252 set 21, 2015 12:30:52 pm org.apache.catalina.core.aprlifecyclelistener lifecycleevent informazioni: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: c:\programmi\java\jdk1.8.0_60\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:/programmi/java/jdk1.8.0_60/bin/../jre/bin/client;c:/programmi/java/jdk1.8.0_60/bin/../jre/bin;c:/programmi/java/jdk1.8.0_60/bin/../jre/lib/i386;c:\programmi\java\jdk1.8.0_60\bin;c:\oracle\ora92\bin;c:\programmi\oracle\jre\1.1.8\bin;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\programmi\ntru cryptosystems\ntru tcg software stack\bin\;c:\programmi\wave systems corp\gemalto\access client\v5\;c:\programmi\gemplus\gemsafe libraries\bin;c:\programmi\file comuni\roxio shared\dllshared\;c:\programmi\file comuni\roxio shared\9.0\dllshared\;c:\programmi\zipgenius 6\;c:\programmi\microsoft sql server\90\tools\binn\;c:\program files\serena\dimensions 14.1\cm\prog;c:\programmi\microsoft\web platform installer\;c:\programmi\git\cmd;c:\programmi\git\mingw32\bin;c:\programmi\git\usr\bin;ant_home%\bin;c:\programmi\nodejs\;c:\documents , settings\gcappella\dati applicazioni\npm;c:\eclipse;;. set 21, 2015 12:30:52 pm org.apache.coyote.abstractprotocol init informazioni: initializing protocolhandler ["http-bio-8080"] set 21, 2015 12:30:52 pm org.apache.coyote.abstractprotocol init informazioni: initializing protocolhandler ["ajp-bio-8009"] set 21, 2015 12:30:52 pm org.apache.catalina.startup.catalina load informazioni: initialization processed in 835 ms set 21, 2015 12:30:52 pm org.apache.catalina.core.standardservice startinternal informazioni: starting service catalina set 21, 2015 12:30:52 pm org.apache.catalina.core.standardengine startinternal informazioni: starting servlet engine: apache tomcat/7.0.64 set 21, 2015 12:30:53 pm org.apache.catalina.loader.webappclassloader validatejarfile informazioni: validatejarfile(c:\documents , settings\gcappella\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps\restful\web-inf\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. see servlet spec 3.0, section 10.7.2. offending class: javax/servlet/servlet.class set 21, 2015 12:30:54 pm org.apache.catalina.startup.tldconfig execute informazioni: @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time. set 21, 2015 12:30:55 pm org.apache.coyote.abstractprotocol start informazioni: starting protocolhandler ["http-bio-8080"] set 21, 2015 12:30:55 pm org.apache.coyote.abstractprotocol start informazioni: starting protocolhandler ["ajp-bio-8009"] set 21, 2015 12:30:55 pm org.apache.catalina.startup.catalina start informazioni: server startup in 3587 ms 

so think problem must in xml...what's wrong it???

upto jersey 2.6 can run java 6(jdk 1.6).

after version 2.6 + onwards need (jdk 1.7) java 7.

for reference: project. functional project please refer below. using jersey 2.6 because production server has java 6 had lower jersey 2.17 2.6.

i invoke sample webserive

localhost:8080/orderstatuswebservice/rest/test/hello-world  

in browser

web.xml

<?xml version="1.0" encoding="utf-8" ?> <web-app xmlns="http://java.sun.com/xml/ns/javaee"           xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"           xsi:schemalocation="http://java.sun.com/xml/ns/javaee            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"           version="2.5">      <display-name>order status rest webservice</display-name>       <servlet>         <servlet-name>jersey-serlvet</servlet-name>         <servlet-class>org.glassfish.jersey.servlet.servletcontainer         </servlet-class>         <init-param>             <param-name>javax.ws.rs.application</param-name>             <param-value>com.xxx.orderstatus.config.orderstatusconfig</param-value>          </init-param>         <init-param>             <param-name>jersey.config.server.provider.scanning.recursive</param-name>             <param-value>true</param-value>         </init-param>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>jersey-serlvet</servlet-name>         <url-pattern>/rest/*</url-pattern>     </servlet-mapping>   </web-app> 

and sample webservice class

package com.xxx.orderstatus.webservice;  import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.queryparam; import javax.ws.rs.core.response;  @path("/test") public class testwebservice  {      @get     @path("/hello-world")     public response checkauth(@queryparam("userid") string  userid) {          return response.status(200).entity("hello").build();     }   } 

and since mine maven project, pom.xml. please note property <finalname>orderstatuswebservice</finalname>

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">     <modelversion>4.0.0</modelversion>     <groupid>com.xxx.orderstatus</groupid>     <artifactid>orderstatuswebservice</artifactid>     <packaging>war</packaging>     <version>1.0-snapshot</version>     <name>orderstatuswebservice maven webapp</name>     <url>http://maven.apache.org</url>     <properties>         <jdk.version>1.6</jdk.version>         <jstl.version>1.2</jstl.version>         <jcl-over-slf4j.version>1.7.5</jcl-over-slf4j.version>     </properties>     <repositories>         <repository>             <id>codelds</id>             <url>https://code.lds.org/nexus/content/groups/main-repo</url>         </repository>         <repository>             <id>maven2-repository.java.net</id>             <name>java.net repository maven</name>             <url>http://download.java.net/maven/2/</url>             <layout>default</layout>         </repository>         <repository>             <id>snapshot-repository.java.net</id>             <name>java.net snapshot repository maven</name>             <url>https://maven.java.net/content/repositories/snapshots/</url>             <layout>default</layout>         </repository>     </repositories>     <dependencies>          <!-- dependencies start -->          <!-- jersey -->         <dependency>             <groupid>org.glassfish.jersey.containers</groupid>             <!-- if container implements servlet api older 3.0, use "jersey-container-servlet-core" -->             <artifactid>jersey-container-servlet</artifactid>             <version>2.6</version>         </dependency>          <!-- jstl -->         <dependency>             <groupid>jstl</groupid>             <artifactid>jstl</artifactid>             <version>${jstl.version}</version>         </dependency>          <!-- jdbc -->         <dependency>             <groupid>com.oracle</groupid>             <artifactid>ojdbc6</artifactid>             <version>11.2.0.3</version>         </dependency>          <!-- gson -->         <dependency>             <groupid>com.google.code.gson</groupid>             <artifactid>gson</artifactid>             <version>2.2.4</version>         </dependency>          <!-- these jars dont' come default latest jerser server container              jars -->         <dependency>             <groupid>javax.servlet</groupid>             <artifactid>servlet-api</artifactid>             <version>2.5</version>             <scope>provided</scope>         </dependency>          <!-- apache commons codec -->         <dependency>             <groupid>commons-codec</groupid>             <artifactid>commons-codec</artifactid>             <version>1.10</version>         </dependency>           <!-- slf4j , log4j libs -->         <dependency>             <groupid>org.slf4j</groupid>             <artifactid>slf4j-log4j12</artifactid>             <version>1.7.12</version>         </dependency>           <!-- apache commons io -->         <dependency>             <groupid>commons-io</groupid>             <artifactid>commons-io</artifactid>             <version>2.4</version>         </dependency>          <!-- multipart dependencies -->         <dependency>             <groupid>org.glassfish.jersey.media</groupid>             <artifactid>jersey-media-multipart</artifactid>             <version>2.6</version>         </dependency>          <!-- commons dbcp 1.4 starts -->         <dependency>             <groupid>commons-dbcp</groupid>             <artifactid>commons-dbcp</artifactid>             <version>1.4</version>         </dependency>            <!-- dependencies ends -->          <dependency>             <groupid>junit</groupid>             <artifactid>junit</artifactid>             <version>3.8.1</version>             <scope>test</scope>         </dependency>     </dependencies>     <build>         <finalname>orderstatuswebservice</finalname>         <plugins>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-compiler-plugin</artifactid>                 <version>2.3.2</version>                 <configuration>                     <source>${jdk.version}</source>                     <target>${jdk.version}</target>                 </configuration>             </plugin>         </plugins>     </build> </project> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -