H:\>java -jar spaceinvaders.jar
If there are exceptions, they will be printed in the console.H:\>set path="C:\Program Files\Java\jdk1.6.0_03\bin"
Main-Class: GameNote: There must be a hard-return at the end of the file, otherwise it will not work.
H:\>jar cmf mainClass.txt spaceinvaders.jar *.class sprites/*.gif
H:\>java -jar spaceinvaders.jar
Image image = Toolkit.getDefaultToolkit().getImage(filename);Instead, create the URL object using
URL url = YourClassName.class.getResource(filename); Image image = Toolkit.getDefaultToolkit().getImage(url);Or, if the code is in a static method of class X, then create the URL with
URL url = X.class.getResource(filename);Now, the resource can be accessed the same way, regardless of whether it is in a JAR or the current directory.
Click here for a working example of Space Invaders!