Stupid JAR Question

I can’t get JAR files to work with my (applet) game. I have compiled my game. The class belong to two packages: com.stefanha.games.boom and com.stefanha.games.util. Now I want to make one JAR file containing all of the classes (from both packages) plus a directory with graphics (GIF images).

I have managed to make a JAR file, but the paths were absolute paths (as in “C:\My Documents\Boom”). Can someone explain the process of creating one JAR file containing all my classes and images, and then making an HTML file that starts the applet from the JAR file?

Thanks, Stefan

http://java.sun.com/j2se/1.4/docs/tooldocs/windows/jar.html

How are you creating the jar file?

Anyways, sounds like you need to use the -C option, make it go to the top directory (above your com hirarchy) and then the path should be relative from there.

Okay, what I’ve done now, after checking out the -C option, is to just copy all my class files to the same location, and to JAR that. It works, BUT I’m having trouble accessing the applet.

My HTML file looks like this:


<html>
<body>
<applet archive="Boom.jar" code="Boom.class" width=320 height=200></applet>
</body>
</html>

I get an error - the VM can’t load/find the class. So I guess that means I need to use its full packaged name, com.stefanha.boom.Boom, but that doesn’t work either.

What is the correct way to run an applet from a JAR file when it is in a package?

from, Stefan

Somebody please answer: it’s so frustrating to have a game ready, but not be able to release it on the internet!

Anyway, if anyone can just describe in general how you can JAR an applet whose class is in a package, and run it from a browser, please answer…

from, Stefan

Use a tag simlar to the one below.


                 <APPLET 
                       CODE=scottshaver.menu.GrowMenu
                       codebase="http://www.scottshaver2000.com/files"
                       ARCHIVE=growmenu.jar
                       WIDTH=200 
                       HEIGHT=125
                 >

Make sure your classes are in the correct directories inside of the jar. You can do that by opening the jar with WinZip or “jar -t jarfile” I think.

Take a look at the jar file that uses the above tag:

http://www.scottshaver2000.com/files/growmenu.jar

or if you don’t use the java-plugin you should try “javac -target 1.1 myJavaFile.java”

mfg
wiesi

You didn’t specify the package in the code= part of the applet tag. You said you were using a package so it should read something like code=“com.stefanha.games.boom.Boom” I assume. Note that you don’t add the “.class”