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 workaroun开发者_运维技巧ds?
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>
精彩评论