PropertiesLauncher and loader.path property issue
See original GitHub issueWhen I created an app. with ZIP layout, I move the lib/ folder outside the jar file and try to run this way. There are some weird behaviors that I see
- I’m setting the
loader.path=lib/in the _application.properties_ file inside the jar, and it’s working. - I’m moving the _application.properties_ file outside the jar, and it’s not working, raising
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getDeclaredMethod(Unknown Source)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:170)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:136)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more
- I’m trying to set the property like
-Dloader.path=lib/but again it’s not working, same error above. - I put the _application.properties_ inside the jar file, and created another one outside the jar, putting other properties in it, and it worked again, read the properties from application.properties file outside the jar file successfully…
Is this expected behavior ?
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
SpringBoot loader.path Unable to load external Jar
My problem is I can't seem to load any JDBC drivers from any jars that I drop into this directory, what am I...
Read more >PropertiesLauncher (Spring Boot 2.4.13 API)
loader.path : a comma-separated list of directories (containing file resources and/or nested archives in *.jar or *.zip or archives) or archives to append ......
Read more >Spring Boot 2 and external libs with the PropertiesLauncher
Spring will use the org.springframework.boot.loader.WarLauncher internally to start the application. But what if you need external libs which ...
Read more >How to use an external JAR in a Spring Boot application
We can instruct the PropertiesLauncher to search for additional JAR files in ... More in detail, we can rely on the property loader.path...
Read more >Spring Boot: Configuring a Main Class - Baeldung
DemoApplication Main-Class: org.springframework.boot.loader. ... Let's see how we can control this property using Maven and Gradle.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you move
application.propertiesto a non-standard location, then you need to useloader.config.locationto tell the launcher where to look. For example-Dloader.config.location=./application.propertiesto look in the current working directory.I would guess that your command line was malformed.
java -jar foo.jar -Dloader.path=lib/won’t work as anything after-jar foo.jaris ignored. For example, you should usejava -Dloader.path=lib/ -jar foo.jarinstead.This sound like standard behaviour for externalised configuration. For general properties (as opposed to those that are property launcher-specific),
application.propertiesinside the jar and outside will be used, with the latter taking precedence. See the documentation on externalised configuration for further details.When the latter is encountered, an exception is thrown and it makes it impossible to read any nested jars so I doubt it’s that. I suspect it’s the former; see https://github.com/spring-projects/spring-boot/issues/2895.
I believe the current behaviour matches that of the JDK. It will ignore non-existent paths that are passed in via
-classpath.That has to be the case. The launcher is responsible for creating the class loader that will load the logging system. For this reason,
PropertiesLauncherwrites logs to System.out whenloader.debugis true.This matches the JDK’s behaviour. For example, if you point
-classpathto a corrupted jar file it doesn’t fail. I can see why that behaviour isn’t ideal in this case, but I’m reluctant to diverge even assuming it’s possible to do so.