[英]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. 我使用firefox版本> 3.5(3.5。 ,3.6。 ,4. *),我尝试正确指定archive
和codebase
属性,但它不起作用。 My main class for applet is situated in the archive
and some necessary classes that are loaded during runtime are situated in the codebase
. 我的applet主类位于archive
,在运行时加载的一些必要类位于codebase
。 If I specify only the archive
then the applet is loaded but the classes from codebase
are missing. 如果我只指定archive
则加载applet但缺少codebase
中的类。 If I specify the archive
and the codebase
then the applet can't be loaded. 如果我指定archive
和codebase
则无法加载applet。 It looks like applet try to load main class from codebase
folder and doesn't look into the archive
file. 看起来applet尝试从codebase
文件夹加载主类,而不是查看archive
文件。
<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 . 主类位于http://myurl.com/archive/myjar.jar ,运行时类位于http://myurl.com/classes 。
Attribute codebase
specifies the base URL of the applet - the directory that contains the applet's code. 属性codebase
指定applet的基本URL - 包含applet代码的目录。 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
. 在archive
属性中搜索jar文件时使用它,以便相对于codebase
搜索archive
属性中的所有jar archive
。
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. 当您使用archive="http://myurl.com/archive/myjar.jar"
和codebase="http://myurl.com/classes"
时,它意味着:找到“ http://myurl.com/archive/ myjar.jar “在” http://myurl.com/classes “文件夹中。
Ie the full search path is " http://myurl.com/classes/http://myurl.com/archive/myjar.jar " . 即完整的搜索路径是“ 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. 此外,如果没有codebase
属性,则无法找到其archive
属性中未指定jar文件的类。 Ie if there is no codebase
then there is no way to find your classes in " http://myurl.com/classes " folder. 即如果没有codebase
,则无法在“ http://myurl.com/classes ”文件夹中找到您的类。
You can find more details in the Deploying With the Applet Tag tutorial. 您可以在使用Applet标记部署教程中找到更多详细信息。
I suggest the following solution : 我建议以下解决方案 :
myjar.jar
in the http://myurl.com/classes
folder; 将myjar.jar
放在http://myurl.com/classes
文件夹中; <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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.