Freek8 Freek8 - 1 year ago 78
Java Question

Creating Java applet using external JARS

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)

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download