views:

103

answers:

1

I am trying to add a JAR file to a simple java applet which can be opened has an HTML.

This is my coding:

applet code="agnicorpcontacts/AgniCorpContactsApp" width="100" height="100" archive="AgniCorpContactsApp.jar">

The location of the JAR file and all of the class files is: C:\Documents and Settings\Owner\My Documents\NetBeansProjects\AgniCorpContacts

Whenever I try to run the file in Internet explorer I get this error:

load: class agnicorpcontacts/AgniCorpContactsApp not found. java.lang.ClassNotFoundException: agnicorpcontacts.AgniCorpContactsApp at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source) at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.FileNotFoundException: C:\Documents and Settings\Owner\My Documents\NetBeansProjects\AgniCorpContacts\dist\agnicorpcontacts\AgniCorpContactsApp.class (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(Unknown Source) at java.io.FileInputStream.(Unknown Source) at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source) at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) ... 7 more Exception: java.lang.ClassNotFoundException: agnicorpcontacts.AgniCorpContactsApp

What do I need to do in order to fix this? Is there a problem with the class path?

+2  A: 

Yes, the problem is about the classpath. You must make your JAR files web accessible (inside your web server or application server), and write the absolute or relative web path to it:

<applet code="MyApplet.class" codebase="mycodeBase" archive="http://myHost/jars/MyApplet.jar"/&gt;

or

<applet code="MyApplet.class" codebase="mycodeBase" archive="/jars/MyApplet.jar"/>

or

<applet code="MyApplet.class" codebase="mycodeBase" archive="../MyApplet.jar"/>

or

<applet code="MyApplet.class" codebase="mycodeBase" archive="MyApplet.jar"/>

You can try if it is web accesible if you write the same URL that your HTML page, and then append the JAR path (e.g. if your HTML file is http:// localhost/hello.html, you should access http:// localhost/AgniCorpContactsApp.jar, if you don't, fix this first)

Next it totally wrong:

You can also declare multiple JAr files, if you hace classpath dependencies (all of them must be web accesible):

<applet code="MyApplet.class" codebase="mycodeBase" archive="MyApplet.jar,externalLib1.jar,externalLib2.jar,externalLib3.jar,externalLib4.jar,etc.jar"/>
greuze