aspose file tools*
The moose likes Applets and the fly likes Help launching an applet created in Netbeans environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Help launching an applet created in Netbeans environment" Watch "Help launching an applet created in Netbeans environment" New topic
Author

Help launching an applet created in Netbeans environment

Jim McGlaughlin
Greenhorn

Joined: Apr 13, 2009
Posts: 4
Hello All,

I am having trouble launching an applet from a HTML page.

I am using the Netbeans environment.

I have two projects.

ivMonitor is a web application and produces a .war file

ivApplets is a library that produces a .jar file
ivApplets has one applet, HelloJim.java which extends JApplet.

The ivMonitor project packages the ivApplets.jar file

When the .war file is deployed I get the following hierarchy of files.

apache\webapps\ivMonitor\testApplet.html
apache\webapps\ivMonitor\WEB-INF\classes
apache\webapps\ivMonitor\WEB-INF\lib\ivmApplets.jar


The ivmApplets.jar file contains the files

classes\HelloJim.class
classes\HelloJim$1.class

The testApplet.html file is



I have tried adding a codebase line with various permutations, to no avail.
HelloJim.java is not in a package.

Below is the error from the JVM from the code above (with .class in the code=).

I can get the 'Caused by:' line below


load: class HelloJim.class not found.
java.lang.ClassNotFoundException: HelloJim.class
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.IOException: open HTTP connection failed:http://localhost:8080/ivMonitor/HelloJim/class.class
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: HelloJim.class


If I change the applet html and drop the '.class' in the code=,


I get a similar, but closer I think, error:

oad: class HelloJim not found.
java.lang.ClassNotFoundException: HelloJim
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.IOException: open HTTP connection failed:http://localhost:8080/ivMonitor/HelloJim.class
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: HelloJim


The real path to the class file is

http://localhost:8080/ivMonitor/WEB-INF/lib/ivmApplets.jar/HelloJim.class

I even tried copying the .jar file from the lib folder to the root of the .war file so it was in the same
folder as the html page, but it still doesn't work.

Any Help would be appreciated.

Thanks!!

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Nothing that's inside of WEB-INF will ever be served to the client, so the jar file must be outside of it. To keep it simple, whichever directory the HTML file is in would be a good place.


classes\HelloJim.class
classes\HelloJim$1.class

There's the problem. In a jar file, the class files must be at the top level, not inside some nested directory. The way applets find their classes (using jar files listed in the archive attribute) is completely different from the way web apps find their classes (using the lib and classes directories).


Ping & DNS - my free Android networking tools app
Jim McGlaughlin
Greenhorn

Joined: Apr 13, 2009
Posts: 4
Thanks for your reply Ulf,

Your answer made me repeat copying the jar file to the folder that had the html page.

This works when the html applet code is

# <applet code="HelloJim" width="200" height="200" archive="ivmApplets.jar" >
# </applet>

and the ivMapplets.jar file is in the same folder as the html.

I'm not sure why it didn't work when I tried this before. Perhaps I did it when I had the code="HelloJim.class" instead of code="HelloJim".

I will have to revise my build scripts so the jar file lands in the right place.

Thanks again.
Hancock Smith
Greenhorn

Joined: Jun 14, 2009
Posts: 1
There seriously has to be a way to have the HTML file that launches the applet in a browser to automatically include the ' archive="yaddayadda.jar" ' attribute in the applet tag. After a new clean and build, the old HTML file is deleted with the clean, requires another recompile following with another execution of the app inside NetbBeans to recreate the HTML file. Does anyone know how to have NetBeans create this HTML file correctly when it's generated automatically? At this point, manually editing the HTML file to reference the .jar file works, but doing this over and over just isn't the glamour that propelled me to use NetBeans.

Thanks

EDIT: I found this link that says how to do it:
http://stackoverflow.com/questions/665820/imported-java-applet-project-into-netbeans-wont-work-netbeans-refuses-to-identi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help launching an applet created in Netbeans environment