简体   繁体   English

Eclipse Export Jar文件不起作用

[英]Eclipse Export Jar file not working

So I've been using java and eclipse for a little while, mostly for my AP class at school. 所以我已经使用java和eclipse了一段时间,主要是在学校的AP课上。 The class is all over now and I've done development on my own. 课堂已经结束,我自己完成了开发工作。 I built a game and I would like to publish it. 我制作了一个游戏,我想发布它。 I looked online on how to do that and I know how to export as a jar file and stuff, but it's not fully running. 我在网上查看了如何执行此操作,并且我知道如何将其导出为jar文件和其他内容,但是它并未完全运行。 When I open up the file, it just has my driver and I cannot interact with it. 当我打开文件时,它只有驱动程序,无法与之交互。 I don't know if it has to do with multiple classes or something like that, but when I open the jar to run my game, it has just the menu screen and then you can't do anything with it. 我不知道它是否与多个类或类似的东西有关,但是当我打开jar运行我的游戏时,它只有菜单屏幕,然后您什么也不能做。 It runs perfectly in eclipse, but not as an export. 它可以在日食中完美运行,但不能作为出口。 I'm sure there's an easy solution, but I couldn't find one. 我敢肯定有一个简单的解决方案,但是我找不到。 I use a mac by the way. 顺便说一下,我使用的是Mac。

Are you using java -jar jarfilename ? 您正在使用java -jar jarfilename吗? If your program is an applet, you could have a wrapper html and use appletviewer to launch it. 如果您的程序是applet,则可以使用包装HTML,并使用appletviewer启动它。

Once you identify what works best, you can put the command in a batch file when distributing it, so that it can be launched easily. 确定最有效的方法后,可以在分发命令时将其放入批处理文件中,以便轻松启动它。

This doesn't look like an error with the jar file export. 这看起来像jar文件导出错误。 Run the jar file with java -jar file.jar and look for errors. 使用java -jar file.jar运行jar文件并查找错误。 I would guess that your game is crashing because it can't find a resource. 我猜你的游戏崩溃了,因为它找不到资源。 Check that you export everything in your jar file and check that all object references are done like this: 检查您是否导出了jar文件中的所有内容,并检查所有对象引用均已完成,如下所示:

protected static Image createImage(String path) {
        URL imageURL = ClassLoader.getSystemClassLoader().getResource(path);

        if (imageURL == null) {
            System.err.println("Resource not found: " + path);
            return null;
        } else {
            return (new ImageIcon(imageURL)).getImage();
        }
    }

This way java will search for the resource in the main directory of the jar file. 这样,java将在jar文件的主目录中搜索资源。 Good luck with your game! 祝您比赛顺利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM