Question

I was wondering if someone could provide me with some background of how exactly the codebase and code tags work when running a java applet.

My problem is this: I have a java applet which comprises of multiple class files over several directories (eg, I have main/applet.class, main/panel.class, geom/shapes.class...). The applet works fine when run from my local hard drive, but now I want to move it to run off of an embedded system. The files in my embedded system would look like this:

+ webs
| - appPage.html
|-+ myApp
  |-+ main
  |   - applet.class
  |   - panel.class
  |-+ geom
      - shapes.class

(It's actually quite a bit bigger than that...). Given that I can load appPage.html from my browser, what would the code and codebase fields of the applet tag look like? (I've tried several combinations, and haven't been able to find any that fit. I keep getting message boxes such as

<applet code = "main/applet.class" codebase="webs/myApp" width=1000 height=700></applet>

but I get a ClassNotFoundException error (main.applet.class). I've searched the web and cannot find a good explanation of exactly what codebase or code are supposed to refer to. Any help would be appreciated (note: I'm new to java and html, so forgive me if I'm missing something obvious).

Was it helpful?

Solution

For the structure shown, this:

<applet 
  code = "main/applet.class" 
  codebase="webs/myApp" 
  width=1000 
  height=700>
</applet>

Should be:

<applet 
  code = "main.applet" 
  codebase="../myApp" 
  width=1000 
  height=700>
</applet>

OTHER TIPS

from HTML applet Tag:

  • codebase: Specifies a relative base URL for applets specified in the code attribute
  • code: Specifies the file name of a Java applet
  • archive: Specifies the location of an archive file

In other words:

code specifies what class in your JAR should be executed in order to start the Applet (this class should extend java.Applet or javax.swing.JApplet). In your case main.applet.class

codebase is the relative URL-path to your JAR-File.

you should also define the archive attribute in <applet> with myApp.jar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top