如何在Java小程序中正确指定代码库和存档?
我用的是firefox版本> 3.5(3.5.,3.6.,4.*),我尝试正确指定 archive
和 codebase
属性,但它不起作用。我的小程序主类位于archive
中,运行时加载的一些必要的类位于codebase
中。如果我仅指定 archive
,则加载小程序,但缺少 codebase
中的类。如果我指定 archive
和 codebase
则无法加载小程序。看起来小程序尝试从 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>
主类位于 http://myurl.com/archive/myjar.jar 中,运行时类位于 http://myurl.com/classes。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性
codebase
指定applet 的基本URL - 包含applet 代码的目录。它在archive
属性中搜索 jar 文件时使用,这样archive
属性中的所有 jar 都会相对于codebase
进行搜索。所以。当您同时使用
archive="http://myurl.com/archive/myjar.jar"
和codebase="http://myurl.com/classes"
时意思是:在中查找 "http://myurl.com/archive/myjar.jar" “http://myurl.com/classes”文件夹。即完整搜索路径为 "http://myurl.com/classes/ http://myurl.com/archive/myjar.jar"。当然找不到!
此外,如果没有
codebase
属性,则无法在archive
属性中指定其 jar 文件的类。即,如果没有codebase
那么就无法在 "http://myurl.com 中找到您的课程/classes" 文件夹。您可以在使用 Applet 标记进行部署教程中找到更多详细信息。
我建议以下解决方案:
myjar.jar
放在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 inarchive
attribute, in such a way that all jars inarchive
attribute are searched relative tocodebase
.So. When you use
archive="http://myurl.com/archive/myjar.jar"
andcodebase="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 withoutcodebase
attribute. I.e. if there is nocodebase
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:
myjar.jar
in thehttp://myurl.com/classes
folder;