File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes simple applet difficulties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "simple applet difficulties" Watch "simple applet difficulties" New topic
Author

simple applet difficulties

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
I have test.html page with this in it
<APPLET codebase="." code="client.Applet.class" archive="applets.jar" width=350 height=200></APPLET>
at the same level I have applets.jar with client.Applet.class

all this is in the root directory of a webapplication(at the same level of the WEB-INF). When I
access it with http://localhost/context1/test.html it fails with the typical ClassNotFound client.Applet.class. Can someone please expalin? tia.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What is the actual name of the applet?
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Originally posted by Keith Lynn:
What is the actual name of the applet?


Hello
It is Applet. Sorry it is not a good name choice. This is for illustration only. I dont know why I am finding this so difficult. I lost my mind on this today.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I don't think it's a good idea to name it Applet, since Applet.java is a class in the hierarchy of the applet.
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Originally posted by Keith Lynn:
I don't think it's a good idea to name it Applet, since Applet.java is a class in the hierarchy of the applet.


Hello
Yes, however in reality in the actual example it is actually called MyApplet. It lives in applets.jar with the full path of client/MyApplet. What I cant figure out is how to call the class when the html is at the same level as archive/jar and whatever its heirarch is in the archive/jar. As I have it, I believe it should be correct, however it fails and my patience is fried.
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
have you tried different paths in your CODEBASE parameter?

For example try using "./" instead of just "."

If that doesn't work, try hardcoding the path during the testing phase. It will help you avoid the burnout and frustration.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The name of the applet doesn't matter here. The problem is that you've put the applet is in WEB-INF. WEB-INF and its subdirectories are for classes and files consumed directly by the web server itself.

Applets don't go there. Applet classes are just plain old files as far as the server is concerned. The web browser requests them by real name, and they are served just as if they were image files, HTML files, etc. The server won't directly serve files from WEB-INF, by design.

So if your applet tag is

<APPLET codebase="." code="client.Applet.class" archive="applets.jar" width=350 height=200></APPLET>

and the applet is embedded in a JSP whose URL is, say

http://myserver.com/products/foo.jsp

then the browser is going to ask for

http://myserver.com/products/applets.jar

and so applets.jar goes at the top level of the "products" webapp.


[Jess in Action][AskingGoodQuestions]
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Thanks to everyone.
The problem was the I couldnt get the packaging striaght in nb5. I finally had to add the jars also as packages so they would be place in the root directory of the webapp.

I now have a further question. How do I write an applet to use a class in an external jar and successfully run in applet viewer or within a webpage. I have imported the external jar classes in the applet, it compiles fine, the external jar is at the same level as the html, it is included in the archive attribute on the applet tag, and still I get the NoClassDefFoundError.

I know this is trival, however I think I have done what is necessary. Can someone point out the missing step? tia
 
Consider Paul's rocket mass heater.
 
subject: simple applet difficulties