How to put a directory first on the classpath with Spring Boot?

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

I am building my Spring Boot application using Maven, so I can start it with:

java -jar myjar-1.0-SNAPSHOT.jar --spring.profiles.active=prod

I want to have a directory first on the classpath that would allow me to place some files on the filesystem without having to unzip the jar to change them.

I have tried using loader.path, but it does not seem to work.

java -Dloader.path="config/*" -jar myjar-1.0-SNAPSHOT.jar --spring.profiles.active=prod

The config dir is a subdirectory of where the jar is located. I am trying to load a keystore file which is injected as a Resource in my application. There is such a file in the src/main/resources, but that only works in my IDE, not when packaged as a jar. So I want to put a file first on the classpath so that that one is found first on the classpath.

回答1:

You can use loader.path but only if the Main-Class is PropertiesLauncher (so it depends how you built the JAR file). Maybe you need to re-build the JAR with packaging=ZIP in the Boot plugin (e.g. docs here)? Can you not set the path to the keystore as a "file:" URL?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!