Here's a complete example
This worked with Win98 + JDK1.3.1 + IE5.00 all installed to default locations. Notes follow.
************************************************************
************************ test.bat ************************
************************************************************
REM *** delete any existing key called "mykey" in the java plugin "cacerts" file
keytool -delete -alias mykey -keystore "C:\Program Files\JavaSoft\JRE\1.3.1\lib\security/cacerts" -storepass changeit
REM *** compile the applet and stick it in a jar
javac HelloApplet.java
jar cvf hello.jar HelloApplet.class
REM *** delete default keystore if already present - we don't know the password
del c:\windows\.keystore
REM *** generate a keypair in the default c:\windows\.keystore
keytool -genkey -alias mykey -keypass password -dname "cn=test" -storepass password
REM *** use the new key to make a signed jar
jarsigner -signedjar hellosigned.jar -storepass password hello.jar mykey
REM *** export the key to a certificate file
keytool -export -alias mykey -file mykey.cer -storepass password
REM *** import the key to the cacerts file used by the plugin
keytool -import -file mykey.cer -keystore "C:\Program Files\JavaSoft\JRE\1.3.1\lib\security/cacerts" -storepass changeit
REM *** make sure we use class file out of jar file
del HelloApplet.class
************************************************************
********************hello.html************************
************************************************************
<HTML><BODY>
<OBJECT classid="clsid:CAFEEFAC-0013-0001-0000-ABCDEFFEDCBA"
codebase="http://java.sun.com/products/plugin/1.3.1/jinstall-131-win32.cab#Version=1,3,1,0">
<PARAM NAME = CODE VALUE = HelloApplet >
<PARAM NAME = ARCHIVE VALUE ="hellosigned.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;jpi-version=1.3.1">
</OBJECT>
</BODY></HTML>
************************************************************
*****************HelloApplet.java*********************
************************************************************
import java.io.*;
import java.applet.*;
public class HelloApplet extends Applet
{
public void init()
{
try {
FileWriter fileout = new FileWriter("hello.txt");// create a new file
fileout.write("Hello");// put some text in the file
fileout.close();
} catch (Exception e) { e.printStackTrace(); }
}
}
************************************************************
NOTES:
Open the html file in your browser and you should get a dialog asking if you want to install and run the applet.
Check the "duke" icon in your taskbar for errors (not browsers java console).
The output file "hello.txt" defaults to location "c:\windows\desktop".
Read the documentation on keytool, jarsigner, and htmlconverter to find out how to get your own code working.
classid and version info in the HTML will vary with the JRE version. Does this lead to compatibility problems?
Bug? The above example only works if the key is called "mykey". If the .bat file is changed to "testkey" the applet fails because the key imported into the "cacerts" file will always be called "mykey", and to get rid of it you must use "keytool -delete -alias mykey ..."
Odd? When the applet is recompiled, the only way to reload the applet is to quit and restart the browser.
Bug? Running jarsigner from the batch file, it appears to hang, but works after hotkey out of the DOS window and back into it.
-Paul

