views:

282

answers:

4

Hi,

I created a JApplet which uses two external libraries (JENA and JUNG). The applet works correctly when i run it from the IDE (using eclipse). I created a jar file, signed it (since the applet needs to read text from disk), created an HTML page to hold the applet, however when i try to run it in a web browser i get the java security warning dialog and when i press run the whole browser tab seems to hang.

Here is the HTML file i wrote:

<html>
   <head>
      <title>Ontology Application</title>
   </head>
   <body>
      <applet code="assignment.Launcher.class" width="1000" height="800" archive="test.jar"></applet>
   </body>
</html>

The Launcher class contains the init, start, stop and destroy methods, and all the classes used in the project are stored in the assignment package. test.jar is the signed jar file and it is placed in the same folder as the HTML file.

I followed the steps in this thread to create my private/public key, certificate and to sign the jar file: How to sign and applet (and get it to work)

I have a list of questions about the whole process since i am unsure about a couple of steps.

Question 1: I created the jar file using eclipse (Right Click project -> export -> JAR file) and kept the default settings. Does the resultant jar file contain the references libraries i imported into the project? if the answer is no, how do i include referenced libraries in the jar file?

Question 2: Should the resultant jar file run if I double click it? since it doesn't run (I think it doesn't work because no main class is specified since an applet doesn't have a main method, but i stand to be corrected)

Question 3: Since I am using external libraries in my applet, do i need to digital sign all the imported jar files in order to make the applet work? or signing the main jar file (containing my classes) is enough?

Question 4: If someday i manage to make the applet work in a browser, will the java security warning dialog pop up every time the application tries to read text from disk? or the security warning dialog shows up only once when the applet is loading?

Thanks in advance, and sorry for asking loads of questions in one thread, however they are closely related to the subject :)

+2  A: 
  1. You should use <PARAM NAME="archive" VALUE='applet.jar, external1.jar, external2.jar'> in your applet declaration in the HTML. You can also try adding Class-Path to your MANIFEST.MF of the main jar (see here)
  2. No. Unless you have a Main-Class specified in your MANIFEST.MF
  3. Yes, in case the external jars do some security-sensitive operations (like reading/writing the file system)
  4. No.
Bozho
Thanks for your answers i'll try your suggestions out and see if i can get it to work.
Spi1988
A: 

In addition to Bozho's answers, you may get some insight by enabling the Java console while testing. It's particularly convenient for reloading the applet without having to restart the browser. This simple example is handy for experimenting, as it's both a signed applet and Java Web Start application, but it runs in the sandbox.

trashgod
A: 

I signed all my jar files and added them to the archive attribute as you told me. However i am still getting this exception:

Exception in thread "thread applet-assignment.Launcher.class-1" java.lang.NoClassDefFoundError: com/hp/hpl/jena/rdf/model/Model

at assignment.InitialiseGUI.<init>(InitialiseGUI.java:149)

at assignment.Launcher.init(Launcher.java:22)

at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)

at java.lang.Thread.run(Unknown Source) 

Caused by: java.lang.ClassNotFoundException: com.hp.hpl.jena.rdf.model.Model

    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 4 more

Caused by: java.io.FileNotFoundException: C:\Users\francois\workspace\EngWebScienceAssignment\bin\com\hp\hpl\jena\rdf\model\Model.class (The system cannot find the path specified)

    at java.io.FileInputStream.open(Native Method)

    at java.io.FileInputStream.<init>(Unknown Source)

    at java.io.FileInputStream.<init>(Unknown Source)

    at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)

    at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)

    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)

    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)

    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)

    at java.security.AccessController.doPrivileged(Native Method)
... 8 more

This is really strange since I tried the whole process on a stub applet with a single external jar file and everything worked like a charm. Dunno what to try next I'm lost :S

Spi1988
A: 

guys thanks for your help, it works now. My mistake was that i forgot to add the last inverted commas at the end of the VALUE attribute in the param tag.

Spi1988