Classloading question

Dear all,

Can somebody pease explain what happens in the situation I describe below?

  • war on payara/server-web:6.2024.12-jdk17
  • class1 in a jar in lib/applibs
  • class1 implements interface class2 which is in the war
  • class3 in the war calls ServiceLoader.load(class1)
  • ClassNotFoundException class2 is not found

I would expect class2 can be found, because it is in the war.

In the stacktrace I can see ServiceLoader.load is using WebappClassLoader.

Am I missing something?

Regards, Eduard

Have a look at Enhanced Classloading :: Payara Community Documentation

Did that already, does not help me with this one. Do you think something special needs to be configured when using ServiceLoader.load?

Hi eduarddrenth,
Your war is using a library. A class in the library extends a class, which is in your war.

In the Payara documentation, I see a comment about applibs:

https://docs.payara.fish/community/docs/Technical%20Documentation/Application%20Development/Class%20Loaders.html

Note: When multiple deployed applications use the same library, they share the same instance of the library. One library cannot reference classes from another library.

This looks exactly like your situation.

My suggestion is to keep the dependencies war → jar.

Petr

That may be it yes and makes sense. I’ll stick to including these libs in WEB-INF/lib. Thanks

1 Like