如何在 Java 小程序中正确指定代码库和存档? [英] How to specify correctly codebase and archive in Java applet?
问题描述
我使用 firefox 版本 > 3.5 (3.5.,3.6.,4.*) 并且我尝试指定 archive
和 codebase
属性正确,但它不起作用.我的小程序的主类位于 archive
中,在运行时加载的一些必要类位于 codebase
中.如果我仅指定 archive
,则小程序已加载,但 codebase
中的类丢失.如果我指定 archive
和 codebase
则无法加载小程序.看起来小程序尝试从 codebase
文件夹加载主类,而不查看 archive
文件.
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>
主类位于 http://myurl.com/archive/myjar.jar 中,运行时类位于在 http://myurl.com/classes 中.
Main class is situated in http://myurl.com/archive/myjar.jar and runtime classes are situated in http://myurl.com/classes.
推荐答案
属性 codebase
指定小程序的基本 URL - 包含小程序代码的目录.它用于在 archive
属性中搜索 jar 文件,以便相对于 codebase
搜索 archive
属性中的所有 jar.
所以.当您将 archive="http://myurl.com/archive/myjar.jar"
和 codebase="http://myurl.com/classes"
一起使用时意思是:找到 "http://myurl.com/archive/myjar.jar" 在"http://myurl.com/classes" 文件夹.
IE.完整的搜索路径是 "http://myurl.com/classes/http://myurl.com/archive/myjar.jar".当然也找不到!
此外,如果没有 codebase
属性,则无法找到其 jar 文件未在 archive
属性中指定的类.IE.如果没有 codebase
,则无法在 "http://myurl.com/中找到您的课程类"文件夹.
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.
您可以在使用 Applet 标签部署教程中找到更多详细信息.
You can find more details in the Deploying With the Applet Tag tutorial.
我建议以下解决方案:
- 将
myjar.jar
放在http://myurl.com/classes
文件夹中; - 假设您的 MyClass.class 位于 default 包中,并且位于 "http://myurl.com/archive/myjar.jar",下面的代码应该可以工作:
- Place
myjar.jar
in thehttp://myurl.com/classes
folder; - 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>
这篇关于如何在 Java 小程序中正确指定代码库和存档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!