Export Applet Java with referenced libraries

梦想与她 提交于 2019-12-24 02:39:07

问题


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.

Error from Java Console :

"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)"

Applet code :

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 code :

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

Really Thanks for help !


回答1:


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

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.



来源:https://stackoverflow.com/questions/7066301/export-applet-java-with-referenced-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!