11

I use firefox version > 3.5 (3.5.,3.6.,4.*) and I try to specify archive and codebase property correctly but it doesn't work. My main class for applet is situated in the archive and some necessary classes that are loaded during runtime are situated in the codebase. If I specify only the archive then the applet is loaded but the classes from codebase are missing. If I specify the archive and the codebase then the applet can't be loaded. It looks like applet try to load main class from codebase folder and doesn't look into the archive file.

<html>    
<body>
<applet width=600 height=300 code="MyClass.class" 
  type="application/x-java-applet;jpi-version=6" 
  archive="http://myurl.com/archive/myjar.jar" 
  codebase="http://myurl.com/classes">
    no applet
</applet>
</body>    
</html>

Main class is situated in http://myurl.com/archive/myjar.jar and runtime classes are situated in http://myurl.com/classes.

MaXal
  • 841
  • 2
  • 8
  • 23
  • 2
    Show us your short but complete example HTML, along with a description of the directory structure containing each of the resources. – Andrew Thompson May 10 '11 at 08:21
  • There is an option (with a `param` tag inside the `applet` tag) to switch the `codebase` off. I believe the old MRJ on the Mac, always ignored the `codebase` if you had an `archive`. / Not sure if the `codebase` requires a trailing `/`. – Tom Hawtin - tackline May 10 '11 at 10:26

1 Answers1

22

Attribute codebase specifies the base URL of the applet - the directory that contains the applet's code. It is used while searching jar files in archive attribute, in such a way that all jars in archive attribute are searched relative to codebase.
So. When you use archive="http://myurl.com/archive/myjar.jar" and codebase="http://myurl.com/classes" together it means: find "http://myurl.com/archive/myjar.jar" in "http://myurl.com/classes" folder.
I.e. the full search path is "http://myurl.com/classes/http://myurl.com/archive/myjar.jar". And of course it can't be found!
Also, classes, whose jar-files aren't specified in the archive attribute, can't be found without codebase attribute. I.e. if there is no codebase then there is no way to find your classes in "http://myurl.com/classes" folder.

You can find more details in the Deploying With the Applet Tag tutorial.

I suggest the following solution:

  1. Place myjar.jar in the http://myurl.com/classes folder;
  2. Assuming your MyClass.class is in default package, and in the "http://myurl.com/archive/myjar.jar", the following code should work:

<html>    
<body>
<applet width=600 height=300 code="MyClass" 
  type="application/x-java-applet;jpi-version=6" 
  archive="myjar.jar" 
  codebase="http://myurl.com/classes">
   no applet
</applet>
</body>    
</html>
MockerTim
  • 2,475
  • 1
  • 25
  • 31
  • 1
    Great answer. :) Re. `classes` directory. I find that confusing & prefer `lib` (which is also shorter ;) ). The `type="application/x-java-applet;jpi-version=6"` also reminded me of [`deployJava.js`](http://docs.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit) to handle the ugly details of deciding exactly what to write according to browser (& browser version) & OS. – Andrew Thompson Jan 14 '13 at 03:20
  • `classes` directory was suggested only to give the faster solution in given conditions. :) Of course `lib` dir should be used instead. – MockerTim Jan 23 '13 at 09:44
  • *"give the faster solution in given conditions"* If the matter were 'service within 6 hours' the OP could not have any complaints. ;) Your answer immediately(1) got my +1. :) 1) Well 'immediately' after I saw it and probably before making the comment. – Andrew Thompson Jan 23 '13 at 09:48
  • @JakeGould Please, do not touch the post if you do not know how to properly format it. Your edit made html invisible! – MockerTim Feb 02 '14 at 21:00
  • 1
    @MockerTim My bad. I saw the `--->` and that seemed like a mistake to me. Can you explain—or provide a link—to explain why that `--->` is needed? – Giacomo1968 Feb 03 '14 at 04:04
  • @JakeGould It's a bypass. I don't remember why. It just worked for me. If you can find the answer yourself, please, let me know. – MockerTim Feb 03 '14 at 05:32