-
Create Applet in Eclipse
Hello,
I need help with creating an applet in eclipse.
When I try to run applet via Run/Run as Applet everything is OK.
But when I create HTML file that call an applet, applet is not displayed.
I think the problem is in navigating to class file in html applet tag.
I use Glassfish v3 server.
My applet tag is:
<applet code="Customer2.class" width="400" height="300"></applet>
Organization of project in eclipse looks as follows:
02_Project
-> Java Resources: src
---> (default package)
------> Customer2.java
---> Libraries
-> JavaScript Resources
-> build
-> Web Content
---> META-INF
------> MANIFEST.MF
---> WEB-INF
------> lib
------> sun-web.xml
---> Customer2.html
When I try "Run/Run on Server" or try open it in web browser (mozilla or ie) through "http://localhost:8080/02_Chapter/Customer2.html", only rectangle was displayed and it announce "Error. Click for details". Details produce this:
load: class Customer2.class not found.
java.lang.ClassNotFoundException: Customer2.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/02_Chapter/Customer2/class.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unk nown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(U nknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknow n Source)
at java.security.AccessController.doPrivileged(Native Method)
... 9 more
Exception: java.lang.ClassNotFoundException: Customer2.class
Organization of files on server:
02_Project
-> META-INF
----> MANIFEST.MF
-> WEB-INF
----> classes
-------> Customer2.class
----> lib
----> sun-web.xml
-> Customer2.html
When I put html and .class files at desktop and open html file, applet was loaded correctly. This is reason why i think that problem is in navigation to .class file in applet tag...
Could somebody explain me what I'm doing wrong?
-
I solve this problem with this solution:
right click at name of project 02_Project/Properties/Java Build Path
and in Source tab I set the default output folder to "02_Project/WebContent/classes"
in html I define applet tag as <applet code="Customer2" codebase="/02_Project/classes" width="400" height="300"></applet>
and it finally works :)
-
Thanks for posting your solution!