Question

I have developed a Jersey Resource class.

Can someone please tell me how can I deploy it on a Web App server. Preferably Tomcat or JBoss.

Or a better question still, can Jersey applications with only a resource class be deployed on a Web App server? If yes, How?

Was it helpful?

Solution

by using web.xml:

<servlet>
    <servlet-name>jersey-servlet</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>com.foo.resources;org.bar.resources</param-value>
    </init-param>
</servlet>

or in Java (without a servlet container):

public class MyConfig extends PackagesResourceConfig {

   public MyApplication() {
      super("com.foo.resources;org.bar.resources");
   }
}

or subclassing Application:

public class MyApplicaton extends Application {

    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        s.add(com.foo.resources.MyResource.class);
        return s;
    }
}  

OTHER TIPS

Deploying in a servlet container will certainly work if you need the servlet container. Simpler and recommended by Jersey is with Grizzly - http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e60

First you need to load your jesey engine to your web application, that can be done by using web.xml, and set loadonstartup as 1.

you can read the first jersery application and configurations here

you can see the simple hello world example here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top