Java Reference
In-Depth Information
Creating a Jersey Project with Eclipse and Tomcat
Problem
You want to create a Jersey-based project in Eclipse and use Tomcat as the container to deploy
your project to.
Solution
Create a web project as you normally would. Add three JARs to the project's configuration:
jersey-bundle-1.0.jar, jsr311-api.jar, and asm-3.1.jar. These are all available from ht-
tps://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0/jersey/dependen-
cies.html ; just click on the links provided to download them. Right-click on the project name
and choose Configure Build Path… to add them as external JARs, and don't forget to add
them to the J2EE module dependencies as well. Once you've created your REST application,
right-click on the project, choose Export…→Web→WAR File, and save the WAR to the Tom-
cat webappsdirectory. Your application will be picked up by Tomcat and deployed. If all goes
well during deployment and all of your dependencies are straight, you'll see some output like
this in the Tomcat console:
Oct 25, 2008 3:38:34 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive restexamples.war
Oct 25, 2008 3:38:34 PM com.sun.jersey.api.core.ClasspathResourceConfig
init
INFO: Scanning for root resource and provider classes in the paths:
C:\programs\tomcat\apache-tomcat-6.0.16\webapps\restexamples\WEB-INF\lib
C:\programs\tomcat\apache-tomcat-6.0.16\webapps\restexamples\WEB-INF\classes
Oct 25, 2008 3:38:34 PM com.sun.jersey.api.core.ClasspathResourceConfig
init
INFO: Root resource classes found:
class com.soacookbook.ProductResource
Oct 25, 2008 3:38:34 PM com.sun.jersey.api.core.ClasspathResourceConfig
init
INFO: Provider classes found:
The output in bold indicates that the deployment knows it is a Jersey application and found a
resource it could instantiate.
Search WWH ::




Custom Search