I am trying to start my first HelloWorld Jersey project by reading a bunch of tutorials on this, and I think that this should work theoretically, but of course I am doing something wrong, that the page gives me a 404 error. Here is what I have:
I started with DynamicWebProject in Eclise and using plugins translated it into a Maven project. And added them to the POM file:
<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.8</version> </dependency> </dependencies>
Then I also added a pretty small class, like this one, to have annotations from Jersey:
import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @Path("/hello") public class HelloWorldResource { @GET @Produces("application/plain") public String getMessage() { // Forward request to service layer. return "Hello World"; } }
and I also registered jersey with them in the web.XML file:
<servlet> <servlet-name>Jersey REST Service</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>JerseyREST</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
NOTE: there were already some created ones, I have not touched them yet. They are still there.
So, with this configuration, I made Run On Server and went to
http://localhost:8080/JerseyREST/rest/hello
but getting the unpleasant HTTP status 404 - / JerseyREST / jerseyrest / rest / hello error on this. And I canβt understand what part I am doing wrong. Any suggestions or places I'm looking at?
Great importance.
Bohn
source share