Export Applet Java with referenced libraries
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 app开发者_运维知识库let 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 !
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.
精彩评论