简体   繁体   English

如何在Java小程序中使用库?

[英]How to use libraries with an Java applet?

The reason I have come here today is because I am experiencing difficulty running my Java applet. 我今天来这里的原因是因为我在运行Java小程序时遇到困难。 The applet of concern uses an external library and runs fine in the IDE; 所关注的applet使用外部库,并且可以在IDE中正常运行; but, will not run properly in the web browser. 但是将无法在网络浏览器中正常运行。

Specifically, it will successfully launch and features non-reliant on the library will run fine; 具体来说,它将成功启动,并且与库无关的功能可以正常运行; but, when using a feature of the library, the applet does nothing. 但是,当使用库的功能时,小程序什么也不做。

The library I am using is contained in jgraphx.jar. 我正在使用的库包含在jgraphx.jar中。 Here is the source code for my HTML file, test.html: 这是我的HTML文件test.html的源代码:

 <HTML>
 <HEAD>
 <TITLE>Test Applet</TITLE>
 </HEAD>
 <BODY>
 Here's my first Java Applet: <BR><BR>

 <applet width="1050" height="550" archive="OAS.jar,lib/jgraphx.jar"
        code="com.OAS.OAS" />

 </BODY>
 </HTML> 

In the same directory I have test.html, OAS.jar, and a folder called lib. 在同一目录中,我有test.html,OAS.jar和一个名为lib的文件夹。 Inside lib is jgraphx.jar. lib内部是jgraphx.jar。

Inside OAS.jar are two folders, COM and META-INF. OAS.jar内有两个文件夹,COM和META-INF。 Inside META-INF is a file named MANIFEST.MF. META-INF内有一个名为MANIFEST.MF的文件。 It contains 它包含

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_07-b11 (Oracle Corporation)
Class-Path: lib/jgraphx.jar

The file structure and manifest files were automatically generated by Netbeans. 文件结构和清单文件由Netbeans自动生成。 I've done a lot of research and tried many different things and in my latest attempt I decided just to let the IDE handle as much as it can. 我已经做了大量研究,并尝试了许多不同的方法,而在最近的尝试中,我决定只让IDE尽可能地处理。

The reason I suspect that the problem is from the library is because in the beginning, the applet would not run on the webpage at all and gave me a message about being unable to access the library. 我怀疑问题出在库中的原因是,从一开始,applet根本不会在网页上运行,并给了我有关无法访问库的消息。 After some tweaking, it now runs; 经过一些调整后,它现在可以运行; but, features requiring the external library appear to not be working. 但是,需要外部库的功能似乎无法正常工作。

Can anybody help with my problem? 有人可以帮忙解决我的问题吗? Is it an issue with the HTML or the manifest files? HTML或清单文件有问题吗? Is it something else entirely? 还有其他事情吗? Any advice would be greatly appreciated. 任何建议将不胜感激。

If you want to run your Applet into Browser than you must have to signed your JAR file first. 如果要将Applet运行到浏览器中,则必须首先签名JAR文件。 Here is the reference for more details: 以下是更多详细信息的参考:

http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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