在JAR(-Xmx)中设置VM选项[JVM启动参数] [英] Setting VM Options in JAR (-Xmx) [JVM Startup Parameters]

查看:1795
本文介绍了在JAR(-Xmx)中设置VM选项[JVM启动参数]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了这个问题,并在stackoverflow本身上找到了很多匹配项,但是其中的答案有些矛盾.

I searched for this question and got many many matches on stackoverflow itself, but the answers in there are sort of contradicting.

问题在于:如何将VM选项添加到jar中?最高投票+接受表示说这是不可能的,也是大多数问题的答案:

In Ques: How to add VM options to jar? the top-voted+accepted says it is not possible and also most of the answers in Ques: Can I set Java max heap size for running from a jar file? say that No, it is not possible. Most of these answers saying "not possible" were given by people with high reputation and therefore I assume they cannot all be just wrong by coincidence.

一个人说可以通过使用据说其他人为此创建了安装程序,或者使用Launch4J或制作批处理文件或制作了另一个JAR,并通过它运行主程序,但是与那些说不"的人.

One guy said that it can be done by using this others said to make a installer for it, or use Launch4J or make batch files or make another JAR and run the main through this but most of these did not get many votes as compared to those saying "no".

那么真的有可能吗?我的问题是我的堆空间用完了,因此我想在JAR中增加它.

So is it really possible or not? My problem is that I run out of heap space and therefore I want to increase it in JAR.

问题1.我已经从netbeans设置了增加的堆空间,JAR也会增加吗? (我认为不,我只是在确认这一事实)

Q2.现在我应该怎么做才能在JAR中增加堆空间? (我正在寻找一种易于执行的方法,因为我不了解批处理脚本以及所有这些知识,而且我已经在放置一个安装程序来放置这些文件(高级安装程序),因此我不想放置其他安装程序来执行此操作)有没有简单的出路?

Q1. I have set increased Heap space from netbeans, will it be increased in the JAR too? (I think no, I am just confirming this one)

Q2. What should I do now to make the increased heap space in JAR? (I am looking for an easy to do way because I do not have knowledge about batch scripting and all and also that I am already putting an Installer to place these files(Advanced Installer) so I do not want to put additional Installers to do this) Is there a simple way out?

推荐答案

A1.从Netbeans运行应用程序时,您会生成一个执行该应用程序的JVM进程.从Netbeans设置堆大小仅意味着它将以您配置的最大堆大小启动JVM.它不会以任何方式影响您正在创建的jar.

A1. When running your application from Netbeans you spawn a JVM process which executes the application. Setting the heap size from Netbeans simply means it will launch the JVM with the max heap size you configured. It will not effect the jar you are creating in any way.

A2.您无法在jar中配置堆大小.这不能通过编程或某些清单配置来完成.
设置最大堆只能通过在启动JVM时传递正确的JVM选项来完成,而这可以通过具有某种启动脚本或使用Java启动器来完成,如在stackoverflow上的许多答案中所述.
在我看来,启动脚本的选项更好,因为它允许最终用户在需要时控制内存设置.使用启动器,内存设置通常是硬编码的,无法更改. 我建议您看一下可用于各种开源Java产品的许多启动脚本.另一种选择是搜索"java启动脚本"或类似的内容.

A2. You cannot configure the heap size inside your jar. This cannot be done either programmatically or by some Manifest configuration.
Setting the max heap can only be done by passing the right JVM options when launching the JVM and this can be done by either having some kind of a startup script or by using a Java launcher as mentioned in the many answers on stackoverflow.
The option of a startup script is better in my opinion as it allows the end user to control the memory setting if needed. With a launcher the memory settings are usually hardcoded and cannot be changed. I suggest you should take a look at the many startup scripts that are available for various open source Java products. Another option would be searching for "java startup script" or similar.

这篇关于在JAR(-Xmx)中设置VM选项[JVM启动参数]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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