Re: [問題] jar 能否加上類似 Xmx 的參數

看板java作者 (Pao)時間19年前 (2006/11/11 17:10), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/6 (看更多)
※ 引述《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
文章代碼(AID): #15LPDqiM (java)
討論串 (同標題文章)
文章代碼(AID): #15LPDqiM (java)