无法将项目提取为可运行的Jar



我正试图将我的游戏提取到一个可运行的.jar文件中,以便在朋友之间进行第一次alpha测试。然而,当我导出时,我得到的应用程序只是打开一个空白帧。在Eclipse中使用Run可以很好地工作。

这是我的静态main:

   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();
}

在你问之前,我确实试过让Main类(在我的清单中选择)不是一个可运行的线程,我确实试过把所有东西减少到一个简单的显示。我知道游戏功能本身没有运行,因为它从来没有达到我分配的内存附近的任何地方。

我的opengl库被提取到jar中。Main类位于processes包中(它也不能与默认包一起使用)。

而且,就像我说的,它是从一个manifest中运行的,该manifest将Main指定为主类(其中包含静态Main)。

我已经对它进行了相当多的修补,我已经将其缩小到所有对Display类的调用,尽管它们在Eclipse中运行得很好。(使用system . exit (0);函数调用后,如果冻结,删除它们。)

添加:我还发现在提取的jar中的lwjgl包中,Display类被分成8个单独的文件。但是,我正在导入opengl.*.

我没有将本机包打包到jar中。

您的代码中有一个隐藏的bug:如果main()抛出异常(当它无法加载本机库时可能会抛出异常),那么您将看不到它。试试这个模式:

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

和移动你的main()代码到新的私有方法run()

如果您的类路径中有commons-lang,那么也可以使用ExceptionUtils.printRootCauseStackTrace()来查看嵌套异常。

最新更新