Java Spring Boot 的外部库文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30745132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
External library folder for Spring Boot
提问by Carlos Alberto
I wonder how to externalize all jdbc drivers for my Spring Boot applications, I would not like to insert jdbc drivers into my fat jar once the application is built.
我想知道如何为我的 Spring Boot 应用程序外部化所有 jdbc 驱动程序,一旦构建了应用程序,我不想将 jdbc 驱动程序插入到我的胖 jar 中。
Is there any way to set a java vm parameter, informing which external folder should be included with jar execution? Or may else exists some kind of spring property for it.
有没有办法设置java vm参数,通知jar执行应该包含哪个外部文件夹?或者可能存在某种弹簧属性。
For example:
例如:
java -DLib=file:\\c:\Drivers -jar sample.jar
采纳答案by Chris White
See the documentation about PropertiesLauncher:
请参阅有关 PropertiesLauncher 的文档:
Looks like you can use the loader.path
property to define a lib folder location, containing jars to load - in fact the lib folder (inline with the jar) is the default location:
看起来您可以使用该loader.path
属性来定义 lib 文件夹位置,其中包含要加载的 jar - 实际上 lib 文件夹(与 jar 内联)是默认位置:
loader.path (if empty) defaults to lib (meaning a local directory or a nested one if running from an archive)
loader.path(如果为空)默认为 lib(如果从存档运行,则表示本地目录或嵌套目录)
回答by Jigish
Isn't that what the classpath is for? As long as the jdbc driver jars are on the classpath, this should work. Something like this:
这不是类路径的用途吗?只要 jdbc 驱动程序 jars 在类路径上,这应该可以工作。像这样的东西:
java -classpath /path/to/driver/jar -jar application.jar
You could also set the CLASSPATH environment variable for the same.
您还可以为此设置 CLASSPATH 环境变量。