• Post Reply Bookmark Topic Watch Topic
  • New Topic

Referring to class in another directory?  RSS feed

 
Zach Burnham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got another one for you all this morning:

I'm writing an applet that needs to send a message to a class in a different directory; the applet is in the Apache htdocs dir, while the class that it needs to talk to is in the Tomcat tree. I've added the path to the directory that the target class is in to CLASSPATH, restarted, but it still will not find the target class.

Any ideas?
 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

what exactally is it saying, i mean what is it complaning about
 
Zach Burnham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's saying it can't find the class.

I've put the target class in a package, let's say it's in /my/path/foo.class. I've put "package my.path;" in the class that it can't find, and put "import my.path.*" in the sending class. It still insists it's not there.

Any help would be appreciated.
 
Zach Burnham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope I'm not breaking any rules by bumping this up to the top, but I'm really stuck here.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a compilation problem? Or a runtime problem? What do you mean by "send a message"?
[ May 03, 2006: Message edited by: Paul Sturrock ]
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing its a compilation problem because of a mistake in the classpath. The classpath needs to have the directory where the base path for the class you want starts. That is if Foo.class is in /tomcat/webapps/myapp/WEB-INF/classes/my/path, the CLASSPATH should contain "/tomcat/webapps/myapp/WEB-INF/classes".
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that applets run on the user's desktop, while servlets and JSPs run on the server. Different JVMs on different machines at different times. CLASSPATH is irrelevant for applets and, for that matter, for servlets -- although when you're compiling, then it can matter, of course.

Classes and JARs in Apache's htdocs directory are just data files, as far as the server is concerned. They can therefore be downloaded to the user's browser on request and executed there.

Class files and JARs in WEB-INF/ cannot, by definition, be downloaded. Tomcat (and all J2EE web containers) refuse to service WEB-INF URLs by design; therefore, it's impossible for any classes in that directory to be downloaded as part of an applet. The only way that a class can be both downloaded and also used in a servlet is for there to be two copies: one in WEB-INF for the servlet, and one in a public web directory to be downloaded as part of the applet.

Now, you said "send a message", and by this you might actually mean applet/servlet communication. I'm sorry to tell you that it's not as simple as this! Because the applet and servlet are on different machines, they have to communicate via some explicit commuications mechanism -- i.e., HTTP requests, a socket connects, RMI, etc.

Understanding what's in the few paragraphs above is a major hurdle that all Java Web developers have to get over early in the game; if you need help understanding, then go ahead and ask questions!
 
Zach Burnham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help, that does make things clearer.

However, I'm kinda screwed, since the whole purpose of this applet is to upload a file to the server for processing, and it sounds like that's going to be difficult, since it would involve some sort of ftp transaction or similar.

Any suggestions?
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most straightforward way is probably to create a Socket connection and then use the appropriate IO datastream for the transfer. It is not that difficult to learn the basics, read the tutorial at java.sun.com, or there is probably one here at the ranch. If you want to implement FTP, probably not necessary here, check out the FTP RFC(rfc959).

Remember that under normal circumstances the applet can only communicate with its originating server.
 
Zach Burnham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion, I've been meaning to learn the networking stuff anyway. Sounds like I'll be able to avoid ftp, at least in this case.

Is it easier to implement FTP from a standalone Java app?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!