How to properly make a runnable jar/exec? [Solved]

My current process was to export the java project as a jar file from eclipse:

http://puu.sh/31ydm.png
(Said that there were some compile warnings)
Then I used Jarsplice:
Added all the necessary Jars -
http://puu.sh/31xY9.png

Added all the natives -
http://puu.sh/31xZx.png

Added the main class and made a fat jar from all of that…

The problem is that it goes to the login screen fine, but when I click login or play offline, it goes to the loading screen window, but abruptly closes.

I have no clue what the problem is :S

(Works fine from eclipse:
yIS7NsAtWxo

Whenever you are having issues with a jar running, go to its directory via a command prompt or terminal and do

java -jar <jarname>.jar

This way, you’ll get the stack trace output when it fails to tell you what the issue is.

How exactly should I get to the directory? (something to do with dir I’m guessing?)
I’m not quite familiar with cmd :S

The command is the same for most DOS and Unix based systems. The Terminal/Command Prompt will start you out in your user directory. So if you have your project in C:\Users\Me\Projects\Game\game.jar and you start out in C:\Users\Me you would type:


cd Projects\Game
java -jar game.jar

‘java’ is not recognized as an internal or external command, operable program or batch file.

Sounds like your system path is messed up. Try this.

EDIT: Add your Java install to the path, it isn’t really clear in that article. For example my JRE is installed to [i]C:\Program Files\Java\jre[/i] although you may have to point it to the bin folder (in jre) I can’t remember.

Thanks a lot dude!

So apparently it can’t find my resources :\

http://puu.sh/31HTY.png

These are the contents of the .jar file:

http://puu.sh/31HZH.png

I think it may have been how I jarspliced it.

Anyone have any suggestions as to how I should do it?

It’s the way you are loading your resources.

public static Image loadImage(String path)
	{
		Image img = null;
                InputStream s = EAnimation.class.getResourceAsStream(path);
		try {
			img = new Image(s, path, false);
		}
		catch (Exception ex) {
			System.err.println("EAnimation:loadImage:Error loading image:"+path);
		}
		
		return img;
	}

This is how I load images, so that they can still be loaded properly by using a jar. Just keep in mind, that where it says:

InputStream s = EAnimation.class.getResourceAsStream(path);

You’ll need to change EAnimation to the class name where you put this method. Also, when specifying the path, you’ll need to give it the absolute path (from your src directory), not the relative path. Also, you don’t have to make it static. I just did that as EAnimation is a utility class, so I wanted to be able to load images without creating an instance of the class.

This is the only reason I could imagine your resources not being loaded. I use jarsplicer all the time, and it doesn’t cause this issue, so I don’t believe it is the problem.

Haha sorry guys, but I found the problem and it was the stupidest problem ever.

One of our guys that quit a while ago made a deferredResourceLoader or w/e, and he had a dedicated jar for the resources so that the method could work, but most of us weren’t really fond of that system so we decided to go with the basic way to load in images/sounds

super.weaponCharacter = new Image("resources/Sprites/WeaponSprites/LE901/LE901_sprite_use.png");

but whenever I tried to jarsplice, it said there were duplicates, so I unknowingly deleted the resources that we ACTUALLY needed – which caused the problem.

But yeah, now it works :smiley:

Thanks for all the help :slight_smile: