Glassfish can't find/instantiate Jersey WebApplicationProviderImpl
I'm trying to create REST services using Jersey (builtin) on Glassfish. I installed GlassFish Server Open Source Edition 3.0.1 (build 22). This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</开发者_JS百科web-app>
However, when I try to deploy the WAR, I get this:
java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [com.sun.jersey.server.impl.container.WebApplicationProviderImpl], because it has not yet been started, or was already stopped
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1367)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.jersey.core.reflection.ReflectionHelper.classForNameWithException(ReflectionHelper.java:236)
at com.sun.jersey.spi.service.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:851)
So what can I do? It looks like a classpath issue, but this is all deep inside glassfish.
I also tried updating the Jersey component in Glassfish to 1.4 as described here, but no change.
Check out the following example from my blog, it may help:
- http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-45.html
My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.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>/rest/*</url-pattern>
</servlet-mapping>
<persistence-context-ref>
<persistence-context-ref-name>persistence/em</persistence-context-ref-name>
<persistence-unit-name>CustomerService</persistence-unit-name>
</persistence-context-ref>
</web-app>
I've found the cause of the problem myself. Apparently, Glassfish gets deeply confused if you deploy a JAR file as a web app, even if you explicitly select the type. The only thing I had to do is change the file suffix to WAR, and it worked (got a different error at first, but one that was much easier to find a solution for).
精彩评论