将JVM参数放在要在运行时拾取的文件中

时间:2022-04-16 14:34:14

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

我正在构建一个当前应用程序的jar,它需要设置几个JVM参数。

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

有没有办法在文件而不是命令行中设置这些JVM参数?

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.

我做了一些狩猎,看起来我可以用java.properties文件做一些事情,可能是通过设置java-args,但我找不到任何对这种格式的引用。

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?

如果没有,还有其他方法来指定JVM参数吗?

3 个解决方案

#1


6  

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.

您当然可以编写批处理脚本来执行JVM。批处理脚本可以查看文件并使用适当的参数进行调用。但这将取决于操作系统。

#2


2  

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

在启动JVM之前,将jar文件shell / bash脚本包装为设置参数和环境变量是很常见的

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

例如在* nix系统上你可以做这样的事情

#!/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


0  

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

如果您使用的是jar文件,则可以设置清单文件并在该文件中提供一些信息(主类等)。

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.

您还可以引用主jar文件使用的其他jar文件。例如。您不希望包含在公司jar文件中的第三方罐子。

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

除此之外其他人都是对的 - 设置批处理文件/脚本。

#1


6  

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.

您当然可以编写批处理脚本来执行JVM。批处理脚本可以查看文件并使用适当的参数进行调用。但这将取决于操作系统。

#2


2  

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

在启动JVM之前,将jar文件shell / bash脚本包装为设置参数和环境变量是很常见的

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

例如在* nix系统上你可以做这样的事情

#!/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


0  

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

如果您使用的是jar文件,则可以设置清单文件并在该文件中提供一些信息(主类等)。

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.

您还可以引用主jar文件使用的其他jar文件。例如。您不希望包含在公司jar文件中的第三方罐子。

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

除此之外其他人都是对的 - 设置批处理文件/脚本。