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>
</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.
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).