如何为可运行的jar添加jvm参数? [英] How to add jvm parameters for a runnable jar?

查看:546
本文介绍了如何为可运行的jar添加jvm参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在创建的可运行的jar它需要xmx1024作为JVM参数。我该怎么办?或者有什么选择吗?

For the runnable jar that i am creating. it requires xmx1024 as JVM argument. How can i do this ? Or is there any alternative ?

推荐答案

您可以为程序打算运行的每个平台提供启动脚本。例如在Linux上,您可以使用 program.sh

You can provide a startup script for each and every platform the program is intended to run on. For example on Linux you can have program.sh

java -mx1024 -jar lib/artifact.jar arg1 arg2

显然,你必须告诉用户程序是打算的要从启动脚本运行,因为如果他们尝试手动启动jar,它将失败。

Obviously you have to tell the user that the program is intended to be run from the startup script, because if they try to manually start the jar it will fail.

如果VM已启动,您甚至可以检入程序所需的参数,如果没有失败。请参阅此答案

You can even check in your program if the VM has been started with the required arguments and fail soon if not. Refer to this answer.

这篇关于如何为可运行的jar添加jvm参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆