Let's say you have a JavaPrograms project in your Eclipse workspace. Inside this project folder you have packages labeled according to the chapters in a textbook. It might look something like the picture at the right. The following describes the procedure for posting an applet on a web server, where ConvertApplet.java is the JApplet driver file and Thermometer.java is a class used by the driver.
These instructions document how to post the applet by exporting it as an archive file, specifically a compressed jar file.
Once you know the program compiles correctly in Eclipse and runs correctly in an applet viewer, then you are ready to start the exporting process.
Here is what to do:
Step 1. Log onto your web server so the archive file can be uploaded.
Step 2. In Eclipse, choose Export from the File menu.
In the Export window, select Jar file and then click Next (not Finish).
|Step 3. In the Jar Export window, click the triangle to the left of the JavaPrograms project to show the contents of JavaPrograms, if you do not see any packages.|
It should now look like the picture at right, if you have clicked on the ch08 package so the contents can be shown in the right window.
However the files ConvertApplet.java and Thermometer.java need to be checked for exporting. See next figure.
Here is the Jar Export window with the proper things selected, but don't name the Jar file yet. Notice how JavaPrograms got a dash and ch08 got a check mark.
Next, you need to click the Browse button.
Step 4. You might decide to name the jar file convert.jar and store it in a directory on the web server called applets. If you did the window would look like this on a Mac OS X machine. A Windows machine would look similar to this.
Once the saving location has been selected and the jar file named, then click Save.
Step 5. Upon saving, you are back in the Jar Export window. Notice the path and file name in the Jar file field. The path name will be different for you since you will have a different share name on your web server and other imbedded folders in the path. In this example, APCSA is the web server share folder and applets is an imbedded folder in the share.
Now just click Finish and the jar file will be saved to the web server.
Note: When Eclipse exports the jar file, byte code files for each java file are automatically generated and placed in the jar file. So in this case, ConvertApplet.class and Thermometer.class files are generated and compressed into the jar file.
Step 6. Since the java files exported were contained in the ch08 package, ch08 must be included in the path for finding the byte code in coding the applet tag in the html file. Here is code that works.
<LI>Enter degrees Fahrenheit or degrees Celsius.
<LI>Click the <STRONG>Convert >>></STRONG> button and the
Celsius equivalent will be displayed.
<LI>Click the <STRONG><<< Convert</STRONG> button and the
Fahrenheit equivalent will be displayed.
<APPLET ARCHIVE = "Convert.jar" CODE="ch08/ConvertApplet.class" WIDTH=250 HEIGHT=100>