如何将系统属性传递给jar文件 [英] How to pass system properties to a jar file
问题描述
我有一个主类,它需要使用-D选项传递的某些属性。我可以通过将它们作为VM选项发送到IDE中来访问它。
I have a main class that expects certain properties that I pass using the -D option. I can access this in my IDE by sending them as VM options.
我使用Maven将此应用程序打包到一个jar文件中,当我尝试以下操作时:
I package this application into a jar file using Maven and when I try the following:
java -jar myjar.jar -Denviroment = dev
或
java -jar myjar.jar-Denvironment = dev
环境系统属性没有被提取。
The enviroment system property is not getting picked up.
关于发生了什么的任何指示?
Any pointers on what is going on?
推荐答案
在 -jar
之前传递参数。如果你在jar文件之后传递它们,它们将被解释为命令行参数并传递给 main
String [] args >。比如,
Pass the arguments before the -jar
. If you pass them after the jar file they are interpreted as command line parameters and passed to the String[] args
in main
. Like,
java -Denviroment=dev -jar myjar.jar
这篇关于如何将系统属性传递给jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!