我可以设置从 jar 文件运行的 Java 最大堆大小吗? [英] Can I set Java max heap size for running from a jar file?

查看:36
本文介绍了我可以设置从 jar 文件运行的 Java 最大堆大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动一个 java jar 文件,它通常需要超过默认的 64MB 最大堆大小.不过,256MB 的堆大小足以满足此应用程序的需求.无论如何要指定(可能在清单中?)在启动 jar 时始终使用 256MB 的最大堆大小?(如果需要,请在下方提供更具体的详细信息.)

I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to specify (in the manifest maybe?) to always use a 256MB max heap size when launching the jar? (More specific details below, if needed.)

这是我用 Java 编写的命令行应用程序,它执行一些图像处理.在高分辨率图像(大约 12 兆像素及以上,这种情况并不少见)上,我收到 OutOfMemoryError.

This is a command-line app that I've written in Java, which does some image manipulation. On high-res images (about 12 megapixels and above, which is not uncommon) I get an OutOfMemoryError.

目前我正在从 jar 文件启动应用程序,即

Currently I'm launching the app from a jar file, i.e.

java -jar MyApp.jar 参数...

我可以通过在命令行上指定 256MB 最大堆大小来避免 OutOfMemoryError,即:

I can avoid an OutOfMemoryError by specifying 256MB max heap size on the command line, i.e.:

java -Xmx256m -jar MyApp.jar 参数...

但是,我不想指定这一点,因为我知道即使对于高分辨率图像,256MB 也足够了.我想将该信息保存在 jar 文件中.这可能吗?

However, I don't want to have to specify this, since I know that 256MB is sufficient even for high-res images. I'd like to have that information saved in the jar file. Is that possible?

推荐答案

你也可以使用像 launch4j 这样的包装器 这将为大多数操作系统生成可执行文件:es 并允许您指定 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.

这篇关于我可以设置从 jar 文件运行的 Java 最大堆大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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