作者pao0111 (Pao)
看板java
标题Re: [问题] jar 能否加上类似 Xmx 的参数
时间Sat Nov 11 17:17:18 2006
※ 引述《tkcn (小安)》之铭言:
: 最近替案主写了一个小工具,
: 为了案主方便,所以我是把程式包成 jar,点两下就可执行
: 但是这支程式,需要用到大量的记忆体,
: 因此,我想请问除了在 console 下 -Xmx 参数外,
: 有没有其他的方式能够设定某 jar 使用的记忆体大小,
: 例如修改 manifest 之类的?
我的搞笑方法...
Launcher.java :
import java.io.IOException;
public class Launcher
{
public static void main(String[] args) throws IOException
{
Runtime r = Runtime.getRuntime();
System.out.println("Total Memory : " + r.totalMemory());
System.out.println("Max. Memory : " + r.maxMemory());
Launcher.lauch("TestApp");
}
public static void lauch(String className) throws IOException
{
String jre = "\"" + System.getProperty("java.home") + "/bin/java.exe\"";
String para = " -Xms256m -Xmx256m";
String cp = " -classpath \"" + System.getProperty("java.class.path") + "\" ";
Runtime.getRuntime().exec(jre + para + cp + className);
}
}
TestApp.java :
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class TestApp
{
public static void main(String[] args)
{
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new GridLayout(2 , 1));
Runtime r = Runtime.getRuntime();
f.add(new JLabel("Total Memory : " + r.totalMemory()));
f.add(new JLabel("Max. Memory : " + r.maxMemory()));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
MANIFEST.MF :
Manifest-Version: 1.0
Main-Class: Launcher
嗯嗯...批次档好像比较简单...XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.113.171.168