如何为jar文件设置最大jvm-memory(XMX) [英] How do I set maximal jvm-memory (XMX) for a jar-file

查看:553
本文介绍了如何为jar文件设置最大jvm-memory(XMX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不向程序中添加额外的批处理脚本的情况下设置最大jvm内存。
答案在下面提供。

How do I set the maximal jvm-memory without adding an extra batch-script to my Programm. Answer is provided below.

推荐答案

这是一个很好的问题,但你的假设很多。我认为你必须记录你的jar名称,以便你的用户调用java -jar xyz.jar,那么你还可以在文档中包含-Xmx256M吗?

It's a good question, but your implmenetation assumes a lot. I presume you have to document the name of your jar for your users to invoke "java -jar xyz.jar" on so can you also include in the documentation that "-Xmx256M" is required?

使用java启动器可能会有更多的运气,例如这个对于Windows,您将启动器配置(路径,最大内存等)放在单独的文件中。对于跨平台,有LaunchAnywhere和其他功能相似的功能。请参阅如何将我的Java程序转换为.exe文件?

You may have more luck using a java launcher, such as this one for Windows, where you put the launcher config (path, max memory etc.) in a separate file. For cross platform, there's LaunchAnywhere, and others, which function similarly. See How can I convert my Java program to an .exe file?

改进现有方案:


  • 使用 java.home 系统属性来解析JDK / JRE的位置

  • 使用 java.class.path 用于设置类路径,类似于 java.library.path 如果您的应用程序需要本机代码。

  • 将传递给主方法的命令参数传递给spanwed进程

  • use the java.home system property to resolve the location of the JDK/JRE
  • use the java.class.path to set up the class path, and similarly for java.library.path if your application requires native code.
  • pass command arguments passed to your main method to the spanwed process

但是,这似乎是很多努力充其量只是一个漏洞的抽象,相反,简单明了的文档就足够了。

But still, this seems to be a lot of effort that at best represents a leaky abstraction, when instead simple and clear documentation would suffice.

这篇关于如何为jar文件设置最大jvm-memory(XMX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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