问题
I've created a Java Applet in Netbeans that uses several external libraries. When I run the applet.java file within Netbeans it works fine and I'm trying to get the same result in a web page.
When I run the automatically created applet.html-file in the build-folder it doesn't load the external library, even though I have specified them in APPLET archive-tag and moved them to the same folder.
Here is my html-file:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="applet/MyApplet.class" width=350 height=200 archive="jcommon-1.0.17.jar, jfreechart-1.0.14.jar, sqljdbc4.jar"></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
The libraries are 3rd-party java (jfreeChart and SQL-JDBC-driver)
回答1:
Creating Java applet using external JARS
Add a reference to them to the archive
attribute of the applet
element.
<APPLET codebase="classes" code="applet/MyApplet.class" width=350 height=200 archive="jcommon-1.0.17.jar, jfreechart-1.0.14.jar, sqljdbc4.jar"></APPLET>
Reformatting that gives:
<APPLET
codebase="classes"
code="applet/MyApplet.class"
width=350
height=200
archive="jcommon-1.0.17.jar, jfreechart-1.0.14.jar, sqljdbc4.jar">
</APPLET>
1.
code="applet/MyApplet.class"
Should be the fully qualified name of the class. If the class name is MyApplet
and the package is applet
, that translates to:
code="applet.MyApplet"
2.
archive="jcommon-1.0.17.jar, jfreechart-1.0.14.jar, sqljdbc4.jar">
Just checking, is applet.MyApplet in jcommon-1.0.17.jar
?
3.
codebase="classes"
That sounds ominous. Is this a full-blown web-app with JSP/servlets? If so, I suspect that path is wrong, in that it is pointing to a place on the server that a client (browser or) applet cannot reach. Try doing a direct fetch (paste the expected address in the browser address bar, and hit 'enter') on each of the applet Jars, if the MyApplet.class
is not in a Jar, do a separate check on the loose class file.
回答2:
package example.jni;
public class HelloWorld {
private static native void writeHelloWorldToStdout();
public static void main(String[] args) {
System.loadLibrary("HelloWorld");
writeHelloWorldToStdout();
}
}
来源:https://stackoverflow.com/questions/8310067/creating-java-applet-using-external-jars