简体   繁体   English

如何在Java applet中正确指定代码库和存档?

[英]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. *),我尝试正确指定archivecodebase属性,但它不起作用。 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. 如果我指定archivecodebase则无法加载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.jarhttp://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 : 我建议以下解决方案

  1. Place myjar.jar in the http://myurl.com/classes folder; myjar.jar放在http://myurl.com/classes文件夹中;
  2. Assuming your MyClass.class is in default package, and in the " http://myurl.com/archive/myjar.jar " , the following code should work: 假设您的MyClass.class在默认包中,并在http://myurl.com/archive/myjar.jar ”中 ,以下代码应该有效:

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

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