执行 swing 客户端时出现 java 内存不足错误
从远程计算机执行时,我的可执行 swing 客户端会抛出内存不足异常。但是,使用以下命令从命令行执行客户端(增加堆空间)是可行的。
java -XMx128m -Xms128m -jar myclient.jar
我不希望远程用户通过命令行使用我的客户端,如上所示。那么,我可以在构建可执行文件时设置这个堆空间吗?我正在使用 Eclipse 的 Fat Jar 插件来创建可执行 jar。
另外,有没有办法为客户端计算机(Windows/Mac/Linux)设置 java 堆空间的默认值?
My executable swing client throws out of memory exception when executed from a remote machine. However, executing the client from command line (increasing the heap space) using the following command works.
java -XMx128m -Xms128m -jar myclient.jar
I do not want the remote users use my client through command line as shown above. So, can I set this heap space while building the executable? I am using Eclipse's Fat Jar Plug-In to create my executable jar.
Also, is there a way to setup a default value for java heap space for client machines(Windows/Mac/Linux)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然我不知道在各个操作系统中设置默认值的方法,但我可以告诉您命令行是 -X 命令的唯一位置。我们在项目中解决这个问题的方法是为他们提供 Windows 安装程序,或者为特定操作系统构建脚本。对于安装程序,我们使用了 NSIS,它似乎工作得非常好。
While I do not know of a way to set a default in the individual OS, I can tell you that the command line is the only place for the -X commands to go. The way we got around that on our project was to give them an installer for windows, or to build them scripts for a particular operating system. For the installer, we used NSIS, which seemed to work really well.
我认为没有一种标准方法可以在应用程序内指定内存设置; java 需要以正确的设置启动。带有清单的 jar 文件由此时已启动的 java 加载。
但是,您可以使用安装程序,请参阅 这个SO问题建议NCIS 。您还可以获取链接(在 Windows 上)或在 Windows 上获取 bat 文件/shell 脚本。或者也许是 Nexus 使用的那种启动器。我做了一些谷歌搜索,发现了 JSW。
因此,总而言之,您的选择似乎是:
我想我会首先将JSW视为一些知名软件就像 Nexus 似乎使用的那样。我不知道它是否适用于桌面应用程序。但尝试一下你就会发现:)
I don't think there is a standard way to specify memory settings from within the application; java needs to start up with the correct settings. The jar file, with manifest, is loaded by java, which has started by then.
You could however use an installer, see this SO question which suggests NCIS. You can also go for a link (on windows) or a bat file / shell script on Windows. Or perhaps the kind of starter Nexus uses. I did some googling and found JSW.
So, in summary, your options seem to be:
I think I would start with looking at JSW as some well-known software like Nexus seems to use that. I don't know whether it works well with desktop apps though. But try and and you'll find out :)
您还可以使用像 launch4j 这样的包装器,它将为大多数操作系统创建可执行文件并允许您指定 VM 选项
you could also use a wrapper like launch4j which will make an executable for most OS:es and allows you to specify VM options
Mac OS X:文章带上你的 Java Mac OS X 应用程序第 1 部分、第 2 部分< /a> 和 第 3 部分 说明如何在 Mac 中嵌入 JAR操作系统应用程序包。您可以在应用程序的属性列表
Info.plist
中指定运行时参数,如 Mac OS X 的 Java Info.plist 关键参考。Mac OS X: The articles Bringing your Java Application to Mac OS X Part 1, Part 2 and Part 3 illustrate how to embed a JAR in a Mac OS application bundle. You can specify run time parameters in the application's property list
Info.plist
, as discussed in Java Info.plist Key Reference for Mac OS X.