java - Can't get Jersey mappings to work -


i new java, have started java coming php.

i trying restful api , running jersey , tomcat. seem make mistake , cannot find post or thread same error message getting. grateful regarding issue, thanks!

this maven dependencies

<dependencies>     <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-grizzly2-http</artifactid>         <version>2.9</version>     </dependency>      <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-grizzly2-servlet</artifactid>         <version>2.9</version>     </dependency>      <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-jdk-http</artifactid>         <version>2.9</version>     </dependency>      <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-simple-http</artifactid>         <version>2.9</version>     </dependency>      <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-jetty-http</artifactid>         <version>2.9</version>     </dependency>      <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-jetty-servlet</artifactid>         <version>2.9</version>     </dependency> </dependencies> 

this web.xml

<servlet>     <servlet-name>javax.ws.rs.core.application</servlet-name> </servlet>  <servlet-mapping>     <servlet-name>javax.ws.rs.core.application</servlet-name>     <url-pattern>/rest/*</url-pattern> </servlet-mapping> 

this code

import javax.ws.rs.path; import javax.ws.rs.get; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype;  @path("/account") public class accountrest {      @get     @produces(mediatype.text_plain)     public string info(){         return "this restful api";     }     @get     @path("/getit")     @produces(mediatype.text_plain)     public string getit(){         system.out.println("got it!");         return "got it!";     } } 

when go url http://localhost:8080/rest/account/getit error message cannot decipher

java.lang.nullpointerexception     org.apache.catalina.loader.webappclassloader.binarynametopath(webappclassloader.java:2496)     org.apache.catalina.loader.webappclassloader.findloadedclass0(webappclassloader.java:2702)     org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1223)     org.apache.catalina.loader.webappclassloader.loadclass(webappclassloader.java:1175)     org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:491)     org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:74)     org.apache.catalina.valves.abstractaccesslogvalve.invoke(abstractaccesslogvalve.java:610)     org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:526)     org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1017)     org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:652)     org.apache.coyote.http11.http11aprprotocol$http11connectionhandler.process(http11aprprotocol.java:277)     org.apache.tomcat.util.net.aprendpoint$socketprocessor.dorun(aprendpoint.java:2451)     org.apache.tomcat.util.net.aprendpoint$socketprocessor.run(aprendpoint.java:2440)     java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)     java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)     java.lang.thread.run(thread.java:745) 

i got work, have been struggling many hours now. article posted above related problem, in 1 of jersey api's. hadn't implemented jersey properly. found guides , tutorials partially explain how implement jersey restful api, made me quite confused.

for meet same issues had, here new setup:

pom.xml

<dependencies>     <!-- servlet 3.0 api -->     <dependency>         <groupid>javax.servlet</groupid>         <artifactid>javax.servlet-api</artifactid>         <version>3.1.0</version>         <scope>provided</scope>     </dependency>     <!-- jax-rs restful web services -->     <dependency>         <groupid>org.glassfish.jersey.containers</groupid>         <artifactid>jersey-container-servlet</artifactid>         <version>2.9</version>     </dependency> </dependencies> 

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">  </web-app> 

restconfig.class

import javax.ws.rs.core.application; import javax.ws.rs.applicationpath; import java.util.hashset; import java.util.set;  @applicationpath("/rest") public class restconfig extends application {      public restconfig(){}      @override     public set<class<?>> getclasses( )     {         final set<class<?>> returnvalue = new hashset<class<?>>( );         returnvalue.add( account.class );         return returnvalue;     } } 

account.class

import javax.ws.rs.path; import javax.ws.rs.get; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype;  @path("/account") public class account {      @get     @produces(mediatype.text_plain)     public string info(){         return "this account restful api";     }      @get     @path("/getit")     @produces(mediatype.text_plain)     public string getit(){         system.out.println("got it!");         return "got it!";     }  } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -