2011-10-23 36 views
0

我想我的遊戲提取到與朋友們我的第一個alpha測試可運行.jar文件。但是,當我導出時,我會得到一個只打開空白框架的應用程序。使用Eclipse中的Run可以正常工作。無法抽取項目作爲運行的JAR

這裏是我的靜態主:

public static void main(String[] args){ 
regular=new DisplayMode(800,600); 
mainframe=new JFrame(); 
mainframe.setSize(new Dimension (regular.getWidth(), regular.getHeight())); 
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); 
mainframe.setLocation(dim.width/2-(regular.getWidth()/2), dim.height/2-(regular.getHeight()/2)); 
ExecutorService exmain = Executors.newFixedThreadPool(1); 
displaycanvas=new Canvas(); 
     displaycanvas.setSize(regular.getWidth(), regular.getHeight()); 
     mainframe.add(displaycanvas); 
     displaycanvas.setFocusable(true); 
     displaycanvas.requestFocus(); 
     displaycanvas.setIgnoreRepaint(true); 
     mainframe.setVisible(true); 
     mainframe.setResizable(true); 
Main datmain=new Main(displaycanvas, mainframe); 
mainframe.addWindowListener(datmain.new maincloser(datmain)); 
mainframe.addComponentListener(datmain.new mainresize(datmain)); 
Thread mainthread= new Thread(datmain); 
mainthread.run(); 
} 

你提問之前,我曾嘗試讓主類(這是在我的清單中選擇)不是一個可運行的線程,我也嘗試將所有問題都下來簡單的顯示。我知道遊戲功能本身沒有運行,因爲它永遠不會到達我分配的內存附近。

我的OpenGL庫被萃取到罐子。 Main類在進程包內(它也不適用於默認包)。

而且,就像我說的,它是從一個清單,其主要分配爲主體的類(靜態主要是)運行。

我已經對它做了很多調整儘管它們在Eclipse的Run中運行良好,但我縮小了它對Display類的所有調用範圍。 (使用System.exit(0);函數調用後,如果它凍結,將其刪除。)

Add:我還發現,在解壓縮jar文件的lwjgl包內,Display類被分成8個獨立的文件。不過,我正在導入opengl。*。

+0

也許會拋出異常...嘗試以環繞用'try/catch語句(例外五)''你的main()'代碼。 –

回答

0

我沒有包裝罐子內的當地人。

0

。在你的代碼隱藏的錯誤:如果main()拋出異常(當它無法加載本地庫,它可能沒有),那麼你就不會看到它。試試這個模式來代替:

public void main(String[] args) { 
    try { 
     MainClass tool = new MainClass(); 
     tool.run(args); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 

和移動你的main()代碼粘貼到新的私有方法run()

如果你在classpath有commons-lang,使用ExceptionUtils.printRootCauseStackTrace()而不是看到嵌套異常了。