JessLilly.com Jess Lilly's home page
Home
Jess Lilly
Jess' Portfolio
Carin Palsrok-Lilly
Amos
Our journeys
Computer info
Links to our friends
Other Links
Contact info

 

Summary: JAR files and packages.
  1. Never set a CLASSPATH variable for use with appletviewer.  The server does not use a CLASSPATH variable, so this will help mimic the server.
  2. 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.  That means... go ahead and JAR up your images and sounds, but not your config files.  I'm sure there is a way to ready other files from the JAR, but I don't know it.
  3. Want to know where to put your html file, how to name your package, what directory to put it in, and how to make the JAR file?  Read solution 1 below.  Solution 2 does not work.
  4. For development purposes, I recommend using SDK 1.1.8 from Sun Microsystems.  I tried using SDK 1.4.1 to create my class files, but the way class files are created in Java 1.4 is not the same as in 1.1.  Class files created with SDK 1.4.1 do not work with older VMs like Microsoft and Java 1.0 and 1.1 Class files created with SDK 1.1.8 work in browsers that have Java the 1.4.1 plug in.  I also recommend for developers, and regular users to install the latest Java version in their internet browser.
  5. Moral of the story:

    I am back to using Java SDK 1.1.8 because it creates class files that work with all Java run time environments.  The JAR files work with SOLUTION 1 and I am just going to leave it alone now.  KISS.

 

Don't bother reading this section.  See the summary above.

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 !

 

 

JessLilly.com  Home