classgraph: ClassGraph on Open Liberty doesn't find any classes from the application.

Here’s Michael from Neo4j-OGM project.

A customer reached out to us wanting to run OGM on Websphere Liberty respectively Open Liberty https://openliberty.io.

Turns out, that Neo4j-OGM doesn’t find any domain classes in that scenario. After a day of pulling my hair, I’m relatively sure that I can boil this down to interactions of ClassGraph and Liberty.

I followed this guide https://openliberty.io/guides/maven-intro.html and added ClassGraph.

Given the following servlet

package io.openliberty.guides.hello;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns="/servlet")
public class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        int numberOfClassesFound = 0;
        // The servlet itself should be found... But isnt.
        try (ScanResult r = new ClassGraph().verbose(true).enableRealtimeLogging().enableAllInfo().whitelistPackages("io.openliberty.guides.hello").scan()) {
            numberOfClassesFound = r.getAllClasses().size();
        }


        response.getWriter().append("Number of classes " + numberOfClassesFound + "\n");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        doGet(request, response);
    }
}

Should find at least 1 class, the servlet itself. However, it does not.

Follow this step to recreate from the attached producer

unzip classgraph-on-liberty.zip -d reproducer
cd reproducer
mvn liberty:dev   

Hit any key after the thing starts or go to http://localhost:9080/ServletSample/servlet

You’ll see 0 classes found respectively a failing test.

I have attached the ClassGraph verbose log as well. What sticks out is:


[09.04.20 18:12:34:743 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.743+0200	ClassGraph	Classloader com.ibm.ws.classloading.internal.ThreadContextClassLoader@47126ba2 is handled by nonapi.io.github.classgraph.classloaderhandler.WebsphereLibertyClassLoaderHandler

[09.04.20 18:12:34:745 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.744+0200	ClassGraph	Found classpath element: /WEB-INF/classes

[09.04.20 18:12:34:745 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.745+0200	ClassGraph	Found classpath element: /Users/msimons/.m2/repository/io/github/classgraph/classgraph/4.8.68/classgraph-4.8.68.jar

[09.04.20 18:12:34:746 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.745+0200	ClassGraph	Classloader com.ibm.ws.classloading.internal.GatewayClassLoader@5ec53685 is handled by nonapi.io.github.classgraph.classloaderhandler.FallbackClassLoaderHandler

[09.04.20 18:12:34:749 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.749+0200	ClassGraph	FallbackClassLoaderHandler did not find classpath entries in unknown ClassLoader com.ibm.ws.classloading.internal.GatewayClassLoader@5ec53685

[09.04.20 18:12:34:750 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.750+0200	ClassGraph	Classloader com.ibm.ws.classloading.internal.AppClassLoader@71f0b71c is handled by nonapi.io.github.classgraph.classloaderhandler.WebsphereLibertyClassLoaderHandler

[09.04.20 18:12:34:750 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.750+0200	ClassGraph	Ignoring duplicate classpath element: /WEB-INF/classes

[09.04.20 18:12:34:750 MESZ] 0000003d io.github.classgraph.ClassGraph                              I 2020-04-09T18:12:34.750+0200	ClassGraph	Ignoring duplicate classpath element: /Users/msimons/.m2/repository/io/github/classgraph/classgraph/4.8.68/classgraph-4.8.68.jar

That liberty Maven thing does something weird with WEB-INF/classes it seems.

The same plugin can produce a runnable jar with mvn liberty:package -Dinclude=runnable that can be started with java -jar target/ServletSample.jar. Going to http://localhost:9080/ServletSample/servlet shows you now the correct number of classes found (1).

classgraph-on-liberty.zip messages.log

The logs are under target/liberty/wlp/usr/servers/guideServer/logs.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

@lukehutch no worries - will do. There’s quite a few people using it, so we can fix quickly if needed.

Thanks again: I can confirm this works with Spring Data Neo4j + OGM on Liberty, too: https://github.com/michael-simons/neo4j-sdn-ogm-with-jax-rs/tree/master/sdn-on-liberty 👍

@cpierceworld Please also verify that your changes don’t break things when you’re running a war file (not an overlay).

I tested it deploying it as a war file as well.