Java: CLASSPATH, JAR files, Images, Packages,
Class files, COBEBASE, CODE, ARCHIVE, getCodeBase(), getDocumentBase()
Appletviewer 1.1 and 1.2 uses CLASSPATH for
appletviewer. Do not set class path. It will help you mimic
what happens on the web server. Appletviewer 1.3 and up does not
use CLASSPATH for this very reason.
A jar file is automatically read from by the
Applet getImage and getAudioClip methods. Objects like
BufferedReader do no automatically read from the jar file.
SOLUTION 1 (works)
Remembery.java
If the package is com.sparkyland.remembery;
On the PC, the java file is in C:\spartique\com\sparkyland\remembery.
On the server, save the java file for backup at ?/public_html/com/sparkyland/remembery.
The jar file should be in the public_html
directory.
The jar file should be created like this.
cd C:\spartique
jar -cvf com\sparkyland\remembery\*.class com\sparkyland\remembery\images\*.gif
... etc.
The html file will be in the public_html directory
and have
applet tag: code="com.sparkyland.remembery.Remebery.Class"
archive="remembery.jar"
and no codebase attribute.
The com/sparkyland/spartique package is still
available because the class loader looks for class files by their
package name from the html file's directory. The spartique package
is not a jar, but a set of class files. It could be a jar file too.
The applet will have a getCodeBase() of http://www.iserv.net/~sparky11/
so you have to 'cd' to com/sparkyland/remembery/sound by building a
string. Then you can use getAudioClip( theURL, theFileName ).
SOLUTION 2 (Does not work)
GOAL: Get all the html and jar files into
the ?/public_html/com/sparkyland/remembery directory. It just
makes sense to have them all in one spot right?
Remembery.java
The package is still com.sparkyland.remembery;
On the PC, the java file is in C:\spartique\com\sparkyland\remembery.
On the server, save the java file for backup at ?/public_html/com/sparkyland/remembery.
The jar file should be in the same ?/public_html/com/sparkyland/remembery
directory.
The jar file should be created like this.
cd C:\spartique\com\sparkyland\remembery
jar -cvf *.class images\*.gif ... etc.
Notice now if you unpacked the jar file, it would
contain the directory structure for images only. It would not
contain the directory structure for com/sparkyland/remembery.
The html file will be in the ?/public_html/com/sparkyland/remembery
directory and have
<applet
archive="com/sparkyland/remembery/remembery.jar"
code="com.sparkyland.remembery.Remembery.class"
codebase="../../.."
width=600 height=400
alt="Java Applet Error OR Browser does not support Java.">
<PARAM name="debug" value="N">
The com/sparkyland/spartique package is still
available because the class loader looks for class files by their
package name from the CODEBASE. The html file is in the com/sparkyland/remembery
directory now, so we need to use ../../../ in codebase to cd back.
Now the class loader will look for
com.sparkyland.remembery.Remembery.class in com/sparkyland/remembery/remembery.jar.
It will also have access to com/sparkyland/spartique.
The spartique package accessable because the
CODEBASE is back at the same point as SOLUTION 1.
getCodeBase() has not changed.
The applet will have a getCodeBase() of http://www.iserv.net/~sparky11/
so you have to 'cd' to com/sparkyland/remembery/sound by building a
string. Then you can use getAudioClip( theURL, theFileName ).
! SOLUTION 2 doesn't work !