简体   繁体   中英

How to specify correctly codebase and archive in Java applet?

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 .

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.
Ie 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. Ie 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM