question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
RaimondKempeescommented, Apr 12, 2020

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

1reaction
michael-simonscommented, Apr 11, 2020

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 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web application hosted in OpenLiberty cannot find classes ...
I have hosted a web application in open liberty and I am trying to class load some third party java classes which are...
Read more >
Class loader configuration :: Open Liberty Docs
You can configure class loading for application to provide access to libraries and third-party APIs that are not provided by the default settings....
Read more >
Getting started to secure a simple Java Microservice with ...
The Microservice runs on OpenLiberty and uses MicroProfile. ... The simplified classdiagram shows an overview of classes of the project for ...
Read more >
io.github.classgraph : classgraph : 4.8.104 - Maven Central
ClassGraph - The uber-fast, ultra-lightweight classpath and module scanner for JVM languages.
Read more >
Troubleshooting tips for Liberty - IBM
Applying fix packs and interim fixes to an archive install ... ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found