2

I have written a Java applet class and made a small HTML page to include it via the <applet>-tag. (This is running locally on my disk drive for the moment) This works well, that is, the applet is being loaded properly. But the applet depends on external libraries (jars). E.g. i imported org.apache.batik.swing.JSVGCanvas; Of course, I have all the jars here and testing the applet from within Eclipse works fine. But the browser (Firefox) doesn't seem to find the jars. How do i tell the browser where to search for the external jars? I tried setting CLASSPATH in the user environment variables. without success. This is on windows XP, running JRE 1.6.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
Scrontch
  • 3,275
  • 5
  • 30
  • 45

2 Answers2

2

Applet is executed in clients machine, so having libs in CLASSPATH won't help.

Libs should be in "archive" attribute:

<applet code="Applet.class" archive="myApplet.jar,lib1.jar,lib2.jar" width="600" height="600" title="MyApplet">
bigGuy
  • 1,732
  • 1
  • 22
  • 37
  • Yes, the libs are in the archive attribute: archive="batik-swing.jar" (amongst others) (forgot to mention that, sorry) But the browser doesn't seem to find them (how would it know the path?): Browser's Java console says: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/batik/swing/JSVGCanvas – Scrontch May 20 '11 at 07:57
  • Good question. Tried with IE8. Doesn't work either. But in IE i can't even access the Java console, so i don't know if it's the same error reason. – Scrontch May 20 '11 at 08:26
  • @Scrontch "how would it know the path?" You set path in "archive" attribute. In my example, all 3 jars must be in the same dir. You can set different paths. For example archive="myApplet.jar,../libs/lib1.jar,../libs/lib2.jar" – bigGuy May 20 '11 at 08:33
  • Ok, so i'm trying to give a complete path in the archive attribute now. But now i get an java.net.MalformedURLException: unknown protocol: d The (Windows) file path on my machine is D:\Dev\batik-1.7. I tried replacing back-slahes with forward-slahes but that didn't solve it. – Scrontch May 20 '11 at 08:41
  • Ok, i have copied the jars over to some other location and using relative paths now (../lib/). This seems to work. I have other unsatisfied dependencies now, but that's another issue. – Scrontch May 20 '11 at 08:48
  • @Scrontch Applets are designed to be distributed entirely over the NETWORK at launch time, so you are simply NOT ALLOWED to specify files on the filesystem of either the client or the server. It doesn't make sense. I hope that helps to explain why Java didn't understand your paths when you tried using a filename instead of a URI. – Robin Green May 20 '11 at 10:09
1

You need to specify the codebase attribute of the applet tag.

Have a look at how-to-specify-correctly-codebase-and-archive-in-java-applet.

It is similar to your question.

Community
  • 1
  • 1
MockerTim
  • 2,475
  • 1
  • 25
  • 31