3
votes

I'm trying to develop JAX-RS under NetBeans 7.4 (which came out today) and GlassFish 4 server.

Apparently NetBeans 7.4 should use Jersey 2.0 however looking at libraries inside the project under libraries->GlassFish Server I see only a couple of generic jars:

  • javax.servlet-api.jar
  • javax.ws.rs-api.jar
  • ...

So I'm not sure whether Jersey and which version is the server using. So the first question is: how do I need to use the same JAX-RS implementation at run time as at compile time or not? and hwo do I know what version I'm using under NetBeans 7.4?

Now using com.sun.jersey.spi.container.servlet.ServletContainer as Servlet class inside web.xml returns

SEVERE:   WebModule[/TestApplication]Error loading WebappClassLoader (delegate=true; repositories=WEB-INF/classes/) com.sun.jersey.spi.container.servlet.ServletContainer

while using org.glassfish.jersey.spi.container.servlet.ServletContainer

SEVERE:   WebModule[/TestApplication]Error loading WebappClassLoader (delegate=true; repositories=WEB-INF/classes/) org.glassfish.jersey.spi.container.servlet.ServletContainer

So the second question is: what is the correct Servlet class?

Adding the libraries Jersey 2.0 downloaded from https://jersey.java.net/download.html under WEB-INF/lib and using the latter Servlet Class yields:

[2013-10-15T18:05:45.136+0200] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=35 _ThreadName=admin-listener(5)] [timeMillis: 1381853145136] [levelValue: 1000] [[
  Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Ref<ContainerRequest>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref<ContainerRequest>, ProcessingProviders)]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Ref<ContainerRequest>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref<ContainerRequest>, ProcessingProviders)]
        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:325)
        at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:177)
        at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:208)
        at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:519)
        at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:505)
        at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:480)
        at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:536)
        at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:216)
        at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
        at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493)
        at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
        at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:356)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
        at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
        at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
        at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
        at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
        at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
        at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
        at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
        at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
        at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
        at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
        at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
        at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
        at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
        at java.lang.Thread.run(Thread.java:722)
]]

EDIT:

Removing libraries from the lib/ folder inside WEB-INF (as Michal Gajdos suggested) avoids runtime errors. Thus the web.xml now is

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/webresources/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

However the JAX-RS still doesn't want to start and nothing is shown on server log. Is there any other directive I'm missing?

Bump!

2

2 Answers

1
votes

Jersey 2 has completely changed way of working see jersey deployment documentation CHPT 4.

First of all there's no web.xml configuration anymore, remove everything you added inside it because it's not needed anymore to start the Jersey server. All you need is to add

@ApplicationPath("webresources")
@Path("/people")
@Stateless
public class PersonResource extends Application
{
 ...
 @GET
    @Path("/getpeople")
    @Produces(
    {
        MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML
    })
  ...

As you can see the @ApplicationPath defined in javax.ws.rs.ApplicationPath substitutes the previous web xml root path configuration and the Resource class must extend application which is defined inside javax.ws.rs.core.Application.

That's it, actually NetBeans 7.4 doesn't help much regarding this and will compile even with a wrong web.xml without any hint unfortunately.

4
votes

The correct HttpServlet class in Jersey 2.x is

org.glassfish.jersey.servlet.ServletContainer

Change your web.xml to use this one and you should be fine.

Note: Your application should not contain libs that are already present on the classpath of GF (it may lead to similar exception as yours).