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)

1
  • 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. Commented Nov 29, 2011 at 11:38

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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 btw
I added it to the original question
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.
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.
0
package example.jni;

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

    public static void main(String[] args) {
        System.loadLibrary("HelloWorld");
        writeHelloWorldToStdout();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.