jersey
  1. jersey
  2. JERSEY-70

Convert examples to use or to work correctly with maven

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: core
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Macintosh

    • Issuezilla Id:
      70

      Description

      I have tested both 0.7 and 0.8 versions of Jersey. Given that there is not maven module for 0.8 I have
      had to try to create it and dependencies.

      With both versions when I try to reproduce the simple HelloWorld example I get:

      com.sun.ws.rest.impl.application.WebApplicationImpl processRootResources
      SEVERE: The ResourceConfig instance does not contain any root resource classes.
      com.sun.ws.rest.api.container.ContainerException: The ResourceConfig instance does not contain any
      root resource classes.
      at
      com.sun.ws.rest.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:4
      51)
      at com.sun.ws.rest.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:370)
      at com.sun.ws.rest.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:318)
      at
      com.sun.ws.rest.impl.container.httpserver.HttpHandlerContainerProvider.createContainer(HttpHandlerC
      ontainerProvider.java:44)
      at
      com.sun.ws.rest.impl.container.httpserver.HttpHandlerContainerProvider.createContainer(HttpHandlerC
      ontainerProvider.java:36)
      at com.sun.ws.rest.api.container.ContainerFactory.createContainer(ContainerFactory.java:118)
      at com.sun.ws.rest.api.container.ContainerFactory.createContainer(ContainerFactory.java:194)
      at com.sun.ws.rest.api.container.ContainerFactory.createContainer(ContainerFactory.java:177)
      at com.sun.ws.rest.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:86)
      at com.sun.ws.rest.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:64)
      at
      net.sf.ehcache.server.resource.EhcacheResourceTest$RESTfulWebServiceThread.run(EhcacheResourceTe
      st.java:55)
      Exception in thread "Thread-6" java.lang.AssertionError: The ResourceConfig instance does not contain
      any root resource classes.
      at org.junit.Assert.fail(Assert.java:71)

      My code and pom can be found at: http://ehcache.svn.sourceforge.net/viewvc/ehcache/trunk/server/
      See EhcacheResource and EhcacheResourceTest

      The following paths are checked:

      /Users/gluck/.m2/repository/org/apache/maven/surefire/surefire-booter/2.3/surefire-booter-2.3.jar
      /Users/gluck/.m2/repository/org/apache/maven/surefire/surefire-api/2.3/surefire-api-2.3.jar
      /Users/gluck/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
      /Users/gluck/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar
      /Users/gluck/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-
      1.0-alpha-7.jar
      /Users/gluck/.m2/repository/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-
      container-default-1.0-alpha-8.jar
      /Users/gluck/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
      /Users/gluck/.m2/repository/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar

      The problem is it does not seem to be checking target/classes where it would find it. Why?

        Activity

        Hide
        sandoz added a comment -

        By default the configuration of the HTTP server scans for java class files in
        directories and jar files declared in the system property java.classpath.

        Since Maven uses other class loading configuration mechanisms a different
        configuration needs to be used with Maven.

        Try this instead:

        PackagesResourceConfig prc = new PackagesResourceConfig(
        "net.sf.ehcache.server.resources");
        HttpHandler h = ContainerFactory.createContainer(HttpHandler.class,
        prc);
        HttpServer s = HttpServerFactory.create("http://localhost/path", h);

        This scans for root resource class files in a set of given packages.

        Show
        sandoz added a comment - By default the configuration of the HTTP server scans for java class files in directories and jar files declared in the system property java.classpath. Since Maven uses other class loading configuration mechanisms a different configuration needs to be used with Maven. Try this instead: PackagesResourceConfig prc = new PackagesResourceConfig( "net.sf.ehcache.server.resources"); HttpHandler h = ContainerFactory.createContainer(HttpHandler.class, prc); HttpServer s = HttpServerFactory.create("http://localhost/path", h); This scans for root resource class files in a set of given packages.
        Hide
        sandoz added a comment -

        This is a deployment configuration issue with Maven and not specifically a bug
        with Jersey.

        See here:

        http://blogs.sun.com/japod/entry/simple_jersey_web_app_with
        http://blogs.sun.com/japod/entry/building_simple_jersey_web_app

        Show
        sandoz added a comment - This is a deployment configuration issue with Maven and not specifically a bug with Jersey. See here: http://blogs.sun.com/japod/entry/simple_jersey_web_app_with http://blogs.sun.com/japod/entry/building_simple_jersey_web_app
        Hide
        gregrluck added a comment -

        Hi

        The HelloWorldWebApp example web.xml config is:

        <?xml version="1.0" encoding="UTF-8"?>
        <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-
        app_2_4.xsd">
        <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/*</url-pattern>
        </servlet-mapping>
        </web-app>

        This does not work in maven.

        To make it work, as the Japod example shows, you need to explicitly configure resource config.
        Applying this to ehcache-server, I get:

        <servlet>
        <servlet-name>Ehcache RESTful Web Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
        </init-param>
        <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>net.sf.ehcache.server.rest.resources</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
        <servlet-name>Ehcache RESTful Web Service</servlet-name>
        <url-pattern>/*</url-pattern>
        </servlet-mapping>

        This now works in Maven.

        I have reopened this bug because I think you should at the least fix your example, otherwise every
        person using this will have this issue.

        Show
        gregrluck added a comment - Hi The HelloWorldWebApp example web.xml config is: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web- app_2_4.xsd"> <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> This does not work in maven. To make it work, as the Japod example shows, you need to explicitly configure resource config. Applying this to ehcache-server, I get: <servlet> <servlet-name>Ehcache RESTful Web Service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name> <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value> </init-param> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>net.sf.ehcache.server.rest.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Ehcache RESTful Web Service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> This now works in Maven. I have reopened this bug because I think you should at the least fix your example, otherwise every person using this will have this issue.
        Hide
        sandoz added a comment -

        We are slowly converting the examples over to maven. I have changed the bug
        title to reflect that.

        See the following in SVN:

        trunk/jersey/samples
        trunk/jersey/samples/helloworld-webapp

        Show
        sandoz added a comment - We are slowly converting the examples over to maven. I have changed the bug title to reflect that. See the following in SVN: trunk/jersey/samples trunk/jersey/samples/helloworld-webapp
        Hide
        sandoz added a comment -

        Fixed

        Show
        sandoz added a comment - Fixed

          People

          • Assignee:
            jersey-issues
            Reporter:
            gregrluck
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: