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

查看:596
本文介绍了我可以设置从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 params ...

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

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

java -Xmx256m -jar MyApp.jar params ...

但是,我不想指定这个,因为我知道256MB就足够了res图像。我想将这些信息保存在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天全站免登陆