aspose file tools*
The moose likes I/O and Streams and the fly likes Another FTP Client Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Another FTP Client Thread" Watch "Another FTP Client Thread" New topic
Author

Another FTP Client Thread

Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
I have done quite a bit of searching on both here and Google and have found a lot of useful FTP Client information.

I have applied quite a bit of it, but keep running into the following exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/net/telnet/TelnetInputStream at newftp.main(newftp.java:12)

Here is a sample code snippet.

As you can see, I have the commons net classes because it does not give an error on the import statement.

The file org/apache/commons/net/telnet/TelnetInputStream.java does exist.

The path org/apache/commons/net/* is in my compiling folder. I am using the command line compiler javac from Java version 1.4.1_05.

Any help would be appreciated. Won't surprise me if it's a classpath error, but I can't seem to set it correctly to work. Thanks.
[ May 13, 2005: Message edited by: Joe Ess ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

If there's no reason to be compiling the source, get rid of that source directory and just include the binary distribution (i.e. zip or jar) in the classpath. If you do want to compile the file from apache commons, add the parent directory of org (or the current directory ".") to the classpath. The compiler will search the classpath for both source and compiled class files. More on how that works in the javac documentation.


[How To Ask Questions On JavaRanch]
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
I already tried "javac -cp . newftp.java" and the error persisted.

Next, per your suggest, I downloaded the zip from Jakarta's website at http://apache.mirrors.versehost.com/jakarta/commons/net/binaries/commons-net-1.4.0.zip and placed it in my compiling folder. Then pulled commons-net-1.4.0.jar out of that zip leaving it in the same folder. Renamed the org folder to org2 just so it would not be read by default of the javac anymore. But now it says [/b]newftp.java:1: package org.apache.commons.net.ftp does not exist
import org.apache.commons.net.ftp.FTPClient;[/b] and I cannot seem to get jar to work to extract the commons jar for some reason.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Did you include commons-net-1.4.0.jar in your classpath? Archives don't get picked up automatically like class files and source files.
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
The jar is in my compile class.. the command I ran at the prompt is as follows.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

No, the classpath in your example is only the current directory. Like I said above, archives don't get picked up automatically. You have to set them in the classpath explicity:
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
Sorry Joe, I mis-understood the last time.

I tried your line, javac is successful. I get the following error when my org folder is renamed org2 as to have it pull this class in from the jar instead..

[ May 13, 2005: Message edited by: Jeff Grant ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

I think the commons jar file isn't where you are telling the compiler it is. Let's go step by step. I saved your code in newftp.java. Put it in a directory with the commons net jar file:


Then I compile the file with this command:


No compile errors and I get a class file:

Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
I agree Joe.. but now go "java newftp". Then I get the following...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Whoops. Wasn't paying attention. You need to set the classpath with java just like with javac.
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
Thank you Joe.. I would have solved all these problems by just tossing the jar in an environmental variable (which I just did) as it would have used that jar for both class paths.

Thanks for your help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Another FTP Client Thread