简体   繁体   中英

Jersey resource classes not being exported

I'm using embedded Jetty with Jersey to form a REST API.

When I export from Eclipse using the Runnable JAR wizard, if I select "Package required libraries into generated JAR", when I run the JAR, I get the error

The ResourceConfig instance does not contain any root resource classes

If I select "Extract required libraries into generated JAR", I get no error, and all the resource classes are detected.

I can't use the Extract method for production due to licensing issues.

Anyone got any fixes or workarounds?

Pre-Requisite : Please verify the package name in the web.xml and your package name where the resource exists in the code. If both are same then follow the solutions :

Solution 1: While exporting the jar please check on the "Add directory entries" checkbox(Eclipse) or filesonly="false" (Ant). This will add the directory entries so that when the jersey code accesses the resource class it is visible to it.

Solution 2: You can specify the class names also. Specifying only the package name didnt work but when I specified like below it worked for me.

<servlet>
    <servlet-name>##SERVLETNAME##</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>##PACKAGENAME##</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>             
        <param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
     </init-param>
     <init-param>
      <param-name>com.sun.jersey.config.property.classnames</param-name> 
      <param-value>
        ##CLASSNAME1##,##CLASSNAME2##
      </param-value> 
    </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>##SERVLETNAME##</servlet-name>
    <url-pattern>/##SERVLETURL##/*</url-pattern>
</servlet-mapping>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM