Putting JVM arguments in a file to be picked up at runtime

风流意气都作罢 提交于 2019-12-10 15:56:33

问题


I'm building a jar of my current application, which required several JVM arguments to be set.

Is there a way of setting these JVM arguments in a file rather than on the command line?

I've done some hunting and it looks like I might be able to do something witha java.properties file, possibly by setting a java-args, but I can't find any reference to the format for doing this.

Am I barking up the wrong tree?

Is this possible and if so how?

If not is there some other way to specify the JVM arguments?


回答1:


You could of course write a batch script to execute the JVM. The batch script could look into the file and call with the appropriate parameters. This would be OS dependent though.




回答2:


It's very common to wrap jar file shell/bash script to setup arguments and enviroment variables before starting the JVM

for example on *nix systems you could do something like this

#!/bin/sh
CLASSPATH=foo.jar:bar.jar
JVMARGS=-some_arg
MYAPP_ARGS=-some_args -for -my -app

java $JVMARGS -classpath $CLASSPATH com.my.domain.myapp $MYAPP_ARGS



回答3:


If you are using a jar file you can setup a manifest file and supply some information (main class etc) in that file.

You can also reference other jar files to be used by your main jar file. E.g. thirdparty jars that you don't want to include in your company jar file.

Aside from that the other guys are right - setup a batch file/script.



来源:https://stackoverflow.com/questions/321140/putting-jvm-arguments-in-a-file-to-be-picked-up-at-runtime

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