Maven is the apt-get for jars. Descriptor-less deployment seems to make plug-n-play more easily. JAX-RS annotations make REST on Servlet platform simpler.
Alright, after several experiment failures, I figured out a way to get Jersey working on Tomcat with help from Maven and Eclipse.
So real stuff:
- Create a "Dynamic Web Project".
- Right click on the new project, "Configure" > "Convert to Maven project...".
- Add Jersey dependency to pom.xml: (this MUST be added with a "compile" scope, "provided" will fail to let Tomcat discover the REST app; for other containers/platforms, read this)
groupId: org.glassfish.jersey.containers
artifactId: jersey-container-servlet
version: 2.5.1 - Save pom, Maven update.
- Create a class extends
javax.ws.rs.core.Application
, annotated withjavax.ws.rs.ApplicationPath
. - Create a class, annotated with
javax.ws.rs.Path
. Individual methods of this class should be properly annotated withjavax.ws.rs.GET
etc. for handling requests.
No comments:
Post a Comment