Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple applet difficulties

 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the actual name of the applet?
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic