如何指定正确codeBase的和归档的Java小程序? [英] How to specify correctly codebase and archive in Java applet?

查看:154
本文介绍了如何指定正确codeBase的和归档的Java小程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用firefox版本> 3.5(3.5的 3.6 的; 4。*),我尝试指定归档 codeBase的属性正确,但它不工作。我对applet的主类位于归档键,可在运行时加载一些必要的类位于 codeBase的。如果我只指定了归档,则小程序被加载但 codeBase的类失踪。如果我指定归档 codeBase的,则小程序无法加载。它看起来像小程序尝试从 codeBase的加载主类文件夹,不看入归档文件

 < HTML和GT;
<身体GT;
<小程序宽度= 600 HEIGHT = 300 code =MyClass.class
  类型=应用程序/ x-j​​ava的小程序,JPI版本= 6
  归档=htt​​p://myurl.com/archive/myjar.jar
  codeBase类=htt​​p://myurl.com/classes>
    没有小应用程序
< /小程序>
< /身体GT;
< / HTML>

主类是坐落在 http://myurl.com/archive/myjar.jar 并运行时类位于在 http://myurl.com/classes


解决方案

属性 codeBase的指定applet的基本URL - 包含applet的$目录C $℃。而搜索在归档属性jar文件中,在归档属性的所有罐子相对于搜索这种方式它是用来到 codeBase的。结果
所以。当您使用归档=htt​​p://myurl.com/archive/myjar.jar codeBase的=HTTP:// myurl.com/classes在一起就意味着:找到 http://myurl.com/存档/ myjar.jar http://myurl.com/classes 文件夹中。结果
即全搜索路径为<一个href=\"http://myurl.com/classes/http://myurl.com/archive/myjar.jar\">http://myurl.com/classes/http://myurl.com/archive/myjar.jar\".当然,它不能被发现!结果
此外,类,它们的JAR文件没有在归档属性指定,不能在没有 codeBase的属性。即如果没有 codeBase的那么有没有办法找到的你的类的 http://myurl.com/classes 文件夹中。

您可以在更多的细节部署利用Applet标记教程。

我建议以下的解决方案


  1. myjar.jar http://myurl.com/classes 文件夹中;

  2. 假设你MyClass.class中的默认的包,并在 HTTP:/ /myurl.com/archive/myjar.jar ,以下code应该工作:


 &LT; HTML和GT;
&LT;身体GT;
&LT;小程序宽度= 600 HEIGHT = 300 code =MyClass的
  类型=应用程序/ x-j​​ava的小程序,JPI版本= 6
  归档=myjar.jar
  codeBase类=htt​​p://myurl.com/classes&GT;
   没有小应用程序
&LT; /小程序&GT;
&LT; /身体GT;
&LT; / HTML&GT;

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.

解决方案

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>

这篇关于如何指定正确codeBase的和归档的Java小程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆