Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
746 views
in Technique[技术] by (71.8m points)

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...