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 Running an applet in Wicket 1.3.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Running an applet in Wicket 1.3.5" Watch "Running an applet in Wicket 1.3.5" New topic
Author

Running an applet in Wicket 1.3.5

mark lar
Greenhorn

Joined: Feb 23, 2010
Posts: 5
Hello,
I've been reading these forums for awhile now, and finally came across an issue that I couldn't find an answer to here, so I figured I might as well ask. I'm trying to add an applet to a Wicket HTML template, but every time I load the page while the webapp is running, the applet fails to load and throws a ClassNotFoundException. Here's the code that's failing :

I thought by placing the applet jar inside of src/main/webapp would be the proper way to get it working. So I did that, compiled it, and deployed it to my Tomcat servlet container. Sure enough, the jar was sitting next to the WEB-INF directory inside of Tomcat/webapps/<MY APP>/. But when I load the page in my browser, it fails. I've tried putting the extracted classes inside of there, and putting the jar in pretty much every directory I can think of. Nothing works. When I load a static html page with the same code (from a directory where the jar is sitting) then it works fine. I'm pretty confused as to what the problem is here...anybody have an idea?

Thanks for reading.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
What is the URL of the page containing the applet? The jar file location is assumed to be relative to that URL. For example, if the URL is

http://localhost:8080/myApp/wicket/AppletPage

then the jar file would need to be in Tomcat/webapps/myApp/wicket.

You might also want to check Tomcat's access logs; it would show at which URLs the browser tries to find the jar file. (You may have to enable the access log in conf/server.xml.)


Ping & DNS - updated with new look and Ping home screen widget
mark lar
Greenhorn

Joined: Feb 23, 2010
Posts: 5
As of right now, my URL to access the applet page is:

http://localhost:8080/<web app name>/app/

This is because of the way my web.xml is setup:



However, there is no 'app' folder inside of Tomcat/webapps/<web app name> directory. Moreover, I can't seem to directly access a class from the URL, something like
http://localhost:8080/<web app name>/app/<path to class>
always results in a 404. What do you think?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
In that case you need to use a CODEBASE attribute in your applet tag - it allows you to use a different directory for your applet resources (like classes and jar files) than the document directory: http://java.sun.com/j2se/1.4.2/docs/guide/misc/applet.html
mark lar
Greenhorn

Joined: Feb 23, 2010
Posts: 5
Does the codebase attribute need to be a URL that can directly access the jar? So something like

codebase="http://localhost:8080/<jar name>.jar" ?

Or do I need to extract all of the individual classes from the jar and make them URL accessible? In the past, when I used a plain old apache server that brought up HTML with PHP in it, then each file inside of my /var/www/html/<app name> directory was accessible through the URL. How exactly do you go about that in Tomcat?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
Codebase points to a directory, not a file. In that directory can be loose class files, but it's much more convenient to put your jar file there that you specify in the archive attribute.

All files you put inside your webapps/myApp directory should be accessible through an URL (as long as they aren't in webapps/myApp/WEB-INF, of course).
mark lar
Greenhorn

Joined: Feb 23, 2010
Posts: 5
So if I have a jar sitting inside of Tomcat/webapps/myapp, I should be able to type in

http://localhost:8080/<My App>/<jar name>.jar

And not get a 404? If that's not working, is there some Tomcat configuration that needs to take place?

Btw, thanks a lot for reading / answering my questions.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
Yes, that should work. Maybe the file has permissions set that prevent it from being served?
mark lar
Greenhorn

Joined: Feb 23, 2010
Posts: 5
I've got it working! I ended up having to set codebase="http://localhost:8080/<App name>" and the applet now loads! Thanks for all of your help. This won't be an issue when it's deployed to a live server will it?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39544
    
  27
That depends on what you mean by "issue" ... if the applet is on a page that is mapped to "/app/" (or something similar) like in this example, then yes, you need the codebase attribute.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running an applet in Wicket 1.3.5
 
Similar Threads
applet code compiles, will not run with local html file
JApplet, Tomcat & Linux
HTTP Status 404 servlet error ("The requested resource is not available")
First Wicket Problem
Apache/Tomcat URL Mapping