1

I have been trying to deploy and run a Jersey2 based REST application on WebSphere ND 8.5. However, it refuses to start up properly and gives the following error:

com.ibm.ws.webcontainer.servlet.ServletWrapper run SRVE8052E: Logging ClassNotFoundException java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer

I tried going through most of the related questions, but none of it was helpful in figuring out the problem.

Some of the links I tried:

As of now, on my local setup the EAR file runs correctly, on a Liberty profile server (embedded in Eclipse). Maven build works fine, and libraries are copied correctly.

One discrepancy I am aware of is that I am using Jersey2.xx, still with the entries in web.xml. But I am not sure how that could cause a ClassNotFoundException.

web.xml for reference:

    <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

      <display-name>MyRestApp</display-name>

      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>

      <servlet>
        <servlet-name>My REST Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.vai.app.rest.main.MyRestApplication</param-value>
        </init-param>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.vai.app.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
        <servlet-name>My REST Application</servlet-name>
        <url-pattern>/rest/api/*</url-pattern>
      </servlet-mapping>
    </web-app>

The weirder thing is this application was at least starting up without this error couple of days back, before an admin "manually removed old files" before re-installing this app on server. This makes me think there was some configuration which got removed/reset during that process which caused this.

How can I make this EAR run without getting this exception on WAS ND 8.5?

Edit: adding full stack trace. I have set the class loading as PARENT_LAST, so I guess it should be using the module's class loader?

[11/22/19 8:40:19:570 CST] 000000b9 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper run SRVE8052E: Logging ClassNotFoundException
                                 java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
    at java.lang.Class.forNameImpl(Native Method)
    at java.lang.Class.forName(Class.java:332)
    at com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:87)
    at com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:122)
    at java.beans.Beans.instantiate(Beans.java:220)
    at java.beans.Beans.instantiate(Beans.java:88)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1489)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java:1478)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.load(ServletWrapper.java:1376)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1027)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4047)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1016)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:213)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:287)
    at com.ibm.ws.ssl.channel.impl.SSLConnectionLink.determineNextChannel(SSLConnectionLink.java:1187)
    at com.ibm.ws.ssl.channel.impl.SSLConnectionLink$MyReadCompletedCallback.complete(SSLConnectionLink.java:694)
    at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1833)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
vaisakh
  • 1,041
  • 9
  • 19
  • Can you post the full stack trace of the ClassNotFoundException? If the jersey-container-servlet-core jar is in the WEB-INF/lib directory, then it should be found - as long as you are loading the class using the web module's classloader. But if you are loading the class using a different classloader, then it would fail. The stack trace might give us some clue while loader is being used. – Andy McCright Nov 22 '19 at 15:19
  • @AndyMcCright, I have updated the question with the stack trace. Also, I have set the class loader policy to PARENT_LAST. Would that ensure that the module class loader is used? – vaisakh Nov 22 '19 at 16:12
  • I wouldn't recommend using PARENT_LAST - it often causes more problems than it solves. But it looks like you are going down a code path where the web container is trying to instantiate a serialized version of the org.glassfish.jersey.servlet.ServletContainer using `Beans.instantiate(...)` rather than loading it directly. That seems wrong to me. Can you try a classloading trace (and/or -verbose:class) to see where that ServletContainer.ser file is getting loaded from? I suspect that maybe it's coming from an older version of Jersey that may need to be deleted from your app's classpath. – Andy McCright Nov 22 '19 at 20:36

0 Answers0