When you need that your applet uses some features like access to client machine files or remote files outer applet base directory it’s mandatory to configure the client virtual machine to allow this(craziest thing) or sign our applet and hope that the user click over «Run» button that appears after the applet loads. Of course the last one option it’s best just because practical reasons.

Now, imagine that we already finish our applet, now we have to pack it to a jar file, that’s just a zip format file with the extension jar. How do that?, simple!, imagine that we gonna pack the ImageViewer applet:

$ jar cf ImageViewer.jar ImageViewer.class ImageTest.jpg

Remember that $ it’s your terminal, command line or whathever prompt, so, don’t write it. The command it’s so simple jar, and the options are «c» that means create a new jar file and «f» means that we gonna indicate the name of the new jar file, in this case «ImageViewer.jar». Next we have ImageViewer.class and ImageTest.jpg which are the files that our applet needs to run. That’s all! now we have a jar file. An important thing to do it’s modify our html page(here just the applet tag) that used to be:

<applet code="ImageViewer.class" width="320" height="240"></applet>

Now become:

<applet code="ImageViewer.class" archive="ImageViewer.jar" width="320" height="240"></applet>

Notice that just added the «archive» stuff, it says to web browser where to find the jar file.

But still we have an unsigned applet, to sign we need first to generate a key, yep, just like our ssh keys and that.

$ keytool -genkey -alias "deathwarrior"

The keytool app it’s provided with the JDK and the options are genkey to(guess what?) generate key and alias which it’s a name that identify that new key, next several data are asked as well a password to secure our keystore and a password for the new key(yes, could be the same).

Now our key is created, let’s sign our applet:

$ jarsigner ImageViewer.jar deathwarrior

Again, jarsigner it’s JDK provided, ImageViewer.jar it’s the jar file that we want to sign and «deathwarrior» it’s the alias of the key which will be used to sign the jar file.

We already done!. Now the applet could be authorized by the user just clicking on the «Run» button and we have access to certain options limited by default.

Hope be helpful.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s