Creating Java applet using external JARS
Asked Answered
A

2

5

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)

Agostino answered 29/11, 2011 at 11:35 Comment(1)
What is your question? Do you have HTML to load the applet? If so, copy/paste the content here, along with any reports form the Java console.Andrew
A
9

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.

Andrew answered 29/11, 2011 at 11:39 Comment(4)
I did this, still it won't load the external jar-files. Thompson, I use the auto-created html file to display the applet in my browser. Applets that are not using external libs are working fine btwAgostino
I added it to the original questionAgostino
applet.MyApplet is not in jcommon.jar. It is the main java file that uses the other 3 jars to display some charts. The program itself is not a full-blown web-app. It is a very basic java applet that retrieves records from a database and creates a graph based on those records.Agostino
It is working now. The codebase was correct, the applet/MyApplet.class was also correct. Turns out I didn't have the jars in the right place.Agostino
T
0
package example.jni;

public class HelloWorld {
    private static native void writeHelloWorldToStdout();

    public static void main(String[] args) {
        System.loadLibrary("HelloWorld");
        writeHelloWorldToStdout();
    }
}
Todhunter answered 7/5, 2012 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.