使用引用的库导出 Applet Java [英] Export Applet Java with referenced libraries

查看:28
本文介绍了使用引用的库导出 Applet Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个需要 1 个库 jar 文件 (prowser-0.2.0) 的小程序.我已经在 eclipse (3.6) 上测试过它并且它可以工作,但是当我把它放在我的 html 网站上时,我收到了以下错误.我从项目属性 => Java 构建路径 => 库 => 添加外部 Jar 导入 pbrowser 库.这段代码在可运行的 jar 中工作,在 Eclipse 中作为小程序工作.

I have coded an applet requiring 1 library jar file (prowser-0.2.0). I have tested it on eclipse (3.6) and it works but when i put it on my html website, i have got the following error. I have impoted pbrowser library from project properties => Java Build Path => Libraries => Add external Jar. This code works in runnable jar and as applet in Eclipse.

来自 Java 控制台的错误:

Error from Java Console :

线程线程小程序-myapplet.class-4"中的异常 java.lang.NoClassDefFoundError: 无法初始化类 com.zenkey.net.prowser.Prowser在 myapplet.init(myapplet.java:8)在 sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(未知来源)在 java.lang.Thread.run(Unknown Source)"

"Exception in thread "thread applet-myapplet.class-4" java.lang.NoClassDefFoundError: Could not initialize class com.zenkey.net.prowser.Prowser at myapplet.init(myapplet.java:8) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source)"

小程序代码:

import java.applet.Applet;
import com.zenkey.net.prowser.*;
public class myapplet extends Applet {

public void init() {

    Prowser prowser = new Prowser();
    Tab tab = prowser.createTab();
    System.out.println(tab.go("http://www.google.com").getPageSource());    

   }
}

HTML 代码:

<html>
<head>
<title> hello world </title>
</head>

<body>
This is the applet:<P>
<applet code="myapplet.class" archive="hello.jar,prowser-0.2.0.jar" width="150" height="50">
</applet>
</body>
</html>

非常感谢您的帮助!

推荐答案

hello.jar 和 prowser-0.2.0.jar 是否与您的 Web 服务器中提供 HTML 的 HTML 文件位于同一目录中?小程序似乎找到了 hello.jar,如您的错误消息所示.prowser-0.2.0.jar 需要作为单独的文件添加到同一目录中, 被打包在 hello.jar 本身中(因为 Eclipse 允许您在选择export as runnable罐子").

Are hello.jar and prowser-0.2.0.jar in the same directory as the HTML file in your web server that serves the HTML? The applet seems to find hello.jar as your error message indicates. The prowser-0.2.0.jar needs to be added to the same directory as a separate file, not being packed inside hello.jar itself (as Eclipse allows you to do if you select "export as runnable jar").

然后我还要检查 hello.jar 的清单文件,看看它是否包含浏览器 Jar 的异常 Class-Path 条目.它不应包含任何相对或绝对路径信息,只包含文件名本身.

Then I'd also check the manifest file of hello.jar to see whether it contains unusual Class-Path entries for the prowser Jar. It should not contain any relative or absolute path information, just the file name itself.

这篇关于使用引用的库导出 Applet Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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