简体   繁体   中英

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. 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. 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. 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.

Are you using java -jar jarfilename ? If your program is an applet, you could have a wrapper html and use appletviewer to launch it.

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. Run the jar file with java -jar file.jar and look for errors. 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:

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. Good luck with your game!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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