如何在 Java Netbeans 平台模块化项目中设置 VM 选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6647275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:37:25  来源:igfitidea点击:

How can I set VM options in a Java Netbeans Platform Modular Project?

javamemorynetbeansjvmplatform

提问by Makoto

I have a Netbeans Platform modular project, not a regular Java project. I want to set VM options to increase memory, but under the "properties" dialog, there is no way to do this for a modular Netbeans platform project. This has cost me huge amounts of time and I still have not found a good way to set the VM args.

我有一个 Netbeans 平台模块化项目,而不是一个普通的 Java 项目。我想设置 VM 选项以增加内存,但在“属性”对话框下,对于模块化 Netbeans 平台项目,无法执行此操作。这花费了我大量的时间,而且我仍然没有找到设置 VM 参数的好方法。

Does anyone know how to set VM args using a Netbeans platform modular project, when compiling and running the program in Netbeans 7? Given the amount of trouble, I am almost ready to give up on Netbeans to create modular applications.

在 Netbeans 7 中编译和运行程序时,有谁知道如何使用 Netbeans 平台模块化项目设置 VM 参数?鉴于麻烦的数量,我几乎准备放弃 Netbeans 来创建模块化应用程序。

采纳答案by JB-

It is quite easy, in fact. Just modify project.propertiesfile to include the following line:

事实上,这很容易。只需修改project.properties文件以包含以下行:

Edited:

编辑:

run.args.extra=-J-Xmx768m

Of course, you can include any other JVM options there.

当然,您可以在其中包含任何其他 JVM 选项。

Enjoy.

享受。

回答by Makoto

I was finally able to solve this based on information at http://activeintelligence.org/blog/archive/gephi-increasing-xmx-memory-in-netbeans/

我终于能够根据http://activeintelligence.org/blog/archive/gephi-increasing-xmx-memory-in-netbeans/上的信息解决这个问题

What I did was modify the project.properties file, as JB said, but the correct way to do it was to add a -J before the args. E.g.,

我所做的是修改 project.properties 文件,正如 JB 所说,但正确的方法是在 args 之前添加一个 -J。例如,

run.args.extra=-J-Xms256m -J-Xmx756m

That did it! Not sure why it took 3 months to figure that out. Definitely a fail for the Netbeans documentation. They should really make this editable from the properties menu instead of making users hunt through nondescript config files!

做到了!不知道为什么花了 3 个月的时间才弄明白。Netbeans 文档绝对是失败的。他们真的应该从属性菜单中进行编辑,而不是让用户搜索不起眼的配置文件!

回答by Syed M Ahmed

I thought i'll put some contribution on this topic, When I was developing a netbeans platform applicationi also faced the same problem, I added run.args.extra=-J-Xmx768m and updated my project.propertiesfile but it didn't ! But when i added run.args.extra=-J-Xmx768m in my platform.propertiesfile then it worked, again this only works when i was in development environment. When I packeged the application for windows the problem remained same my min heap size was 24m and max is 64m. Then I found out that if I update and add default_options="--branding my_project -J-Xms64m -J-Xmx1G" in my_project.confin my installed directory C:\Program Files\my_project\etc then run my application and checked the ide log i can now see the change. By the way i wasn't lucky enough to see even the run node when i right click and go to the project properties dialogue in netbeans 7.0.1. Its upto netbeans dream team to make us feel lucky.

我想我会在这个主题上做一些贡献,当我开发一个netbeans 平台应用程序时,我也遇到了同样的问题,我添加了 run.args.extra=-J-Xmx768m 并更新了我的project.properties文件,但它没有!但是当我在我的platform.properties文件中添加 run.args.extra=-J-Xmx768m 时,它就起作用了,同样,这只在我处于开发环境中时起作用。当我为 Windows 打包应用程序时,问题仍然相同,我的最小堆大小为 24m,最大为 64m。然后我发现如果我在my_project.conf 中更新并添加 default_options="--branding my_project -J-Xms64m -J-Xmx1G"在我安装的目录 C:\Program Files\my_project\etc 然后运行我的应用程序并检查 ide 日志我现在可以看到更改。顺便说一句,当我右键单击并转到 netbeans 7.0.1 中的项目属性对话框时,我什至没有看到运行节点。它由 netbeans 梦之队让我们感到幸运。

回答by Billy D

I had this issue and after some digging around and reading a lot of docs I was able to deduce that most of those values were coming from templates in the harness.

我遇到了这个问题,经过一番挖掘和阅读大量文档后,我能够推断出大多数这些值来自工具中的模板。

So if you go to your IDE_home/harness/etc/ you will find the "app.conf" file. This file is renamed during a distro build and the "app.conf" becomes your "application name.conf". Edit this file with the default values you would like in you application.

因此,如果您转到 IDE_home/harness/etc/,您将找到“app.conf”文件。该文件在发行版构建期间被重命名,“app.conf”成为您的“应用程序名称.conf”。使用您希望在应用程序中使用的默认值编辑此文件。

In my case I replaced the line that read: default_options="--branding ${branding.token} -J-Xms24m -Xmx64m" with default_options="--branding ${branding.token} -J-Xms64m -Xmx512m" as my application was needing more memory. By changing the template I dont have to touch every deployment and change the memory CLI for the VM.

在我的情况下,我用 default_options="--branding ${branding.token} -J-Xms64m -Xmx512m" 替换了以下行: default_options="--branding ${branding.token} -J-Xms24m -Xmx64m"我的应用程序需要更多内存。通过更改模板,我不必接触每个部署并更改 VM 的内存 CLI。

Hope this helps!

希望这可以帮助!

回答by lopisan

For maven projects:

对于 Maven 项目:

As described in this question, you can use etcConfFileparameter of nbm-maven-plugin:

如本问题所述,您可以使用nbm-maven-plugin 的etcConfFile参数:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <configuration>
        <etcConfFile>src/main/resources/app.conf</etcConfFile>
    </configuration>
</plugin>

More info: Geertjan's Blog

更多信息:Geertjan 的博客

回答by arash

you have to add these lines to your project properties file.

您必须将这些行添加到您的项目属性文件中。

<target name="build-launchers" depends="suite.build-launchers">
<replace file="build/launcher/etc/${app.name}.conf" token="--branding graphsimulator -J-Xms24m -J-Xmx64m" value="--branding graphsimulator -J-Xms128m -J-Xmx512m"/>
</target>

回答by Vishrant

If you want to use Netbeans to set the VM options without bothering about which file to edit, here we go:

如果您想使用 Netbeans 设置 VM 选项而不必担心要编辑哪个文件,请执行以下操作:

Run -> Set project configuration -> VM Options

Add your option in the corresponding text box for example: -Xms10m

在相应的文本框中添加您的选项,例如:-Xms10m

To answer user1156544doubt:

回答user1156544疑问:

enter image description here

在此处输入图片说明