Home > Software design >  Reasons why a JAR on classpath not loaded
Reasons why a JAR on classpath not loaded

Time:05-26

I have a SpringBoot application that is run with the command java -classpath <longlist of JARs> com.example.MyApp.

I have the path to a JAR - in this case liquibase-core-4.4.0.jar - specified on the classpath. However, on startup the app complains about missing class definitions.

Attaching a debugger I can see that the URLClassPath does have this JAR in its path list. However, there is no loader for it.

What would cause a JAR to be on the classpath but have no loader?

CodePudding user response:

Spring boot applications have pretty clever system of class path searching, for example it finds jars in BOOT-INF/lib - something that a regular java system can't do. So spring has custom class loaders for this purpose.

Now its possible to add an external jar with the help of LOADER_PATH environment variable or loader.path parameter.

Bottom line, instead of using "standard" java mechanism, consider using "special" spring boot's mechanisms.

Read the official documentation for concrete examples

  • Related