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.

Use the same classpath ordering for an exploded jar and an archive

See original GitHub issue

demo.zip

Print classloader urls in main method:

	public static void main(String[] args) {
		URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
		for(URL url : classLoader.getURLs()) {
			System.err.println(url);
		}
		SpringApplication.run(DemoApplication.class, args);
	}
  • Run as jar
mvn clean package -DskipTests
$ java -jar target/demo-0.0.1-SNAPSHOT.jar

output:

jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-starter-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-context-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-aop-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-beans-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-expression-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-autoconfigure-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-boot-starter-logging-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/logback-classic-1.1.11.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/logback-core-1.1.11.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/jcl-over-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/jul-to-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/log4j-over-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/snakeyaml-1.17.jar!/
jar:file:/private/tmp/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/slf4j-api-1.7.25.jar!/
  • Run in directory
cd target
unzip demo-0.0.1-SNAPSHOT.jar -d demo
cd demo
java org.springframework.boot.loader.PropertiesLauncher

output:

file:/private/tmp/demo/target/demo/BOOT-INF/classes/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/jcl-over-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/jul-to-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/log4j-over-slf4j-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/logback-classic-1.1.11.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/logback-core-1.1.11.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/slf4j-api-1.7.25.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/snakeyaml-1.17.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-aop-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-beans-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-boot-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-boot-autoconfigure-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-boot-starter-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-boot-starter-logging-1.5.3.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-context-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-core-4.3.8.RELEASE.jar!/
jar:file:/private/tmp/demo/target/demo/BOOT-INF/lib/spring-expression-4.3.8.RELEASE.jar!/

The order of classLoader urls is very important.

When run app in exploded directory, the order of jars is different.

I recommend add a index file BOOT-INF/INDEX.LIST to save the order of jars.

See also:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:23 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Jul 11, 2019
0reactions
philwebbcommented, Jan 21, 2020

I’ve opened #19847 for the Gradle part.

Read more comments on GitHub >

github_iconTop Results From Across the Web

It's possible to add/load an exploded war to a stand-alone java ...
You need a few things on the classpath: WEB-INF/classes - This contains all your custom classes from the WAR; All the jars of...
Read more >
Extracting the Contents of a JAR File
Let's look at the options and arguments in this command: The x option indicates that you want to extract files from the JAR...
Read more >
The Executable Jar Format - Spring
A classpath. idx file can be provided for both jars and wars, and it provides the ordering that jars should be added to...
Read more >
Jar file real path in non-exploded ear - JBoss.org
We deploy our application as a non-exploded ear archive. ... 'real' locations to specify on the classpath in order to compile successfully.
Read more >
Understanding the Tomcat Classpath - Common problems ...
To add a single JAR file as a class repository, use the following format: "file:/path/to/foldername/jarname.jar"; To call environment variables, use the ${} ...
Read more >

github_iconTop Related Medium Post

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