Hello,
I am trying to create a simple ftp client. I'm following the instructions from http://www.nsftools.com/tips/JavaFtp.htm(option 4)

If you take look at JakartaWrapperTest.java, The first line is
import JakartaFtpWrapper;

So When do javac JakartaFtpWrapper.java JakartaWrapperTest.java -cp commons-net-ftp-2.0.jar I get an error saying '.' expected.

And if I comment out the import line I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient

What am I doing wrong? I hope there is a simple solution to this.
Many thanks in advance.

do you've org.apache.commons.net.ftp.FTPClient jar in your classpath?

PS: what IDE are you using?

Download commons-net-1.4.1.jar file and put it in your classpath. Your compiler will stop crying. I am using eclipse and here i am able to compile the same code smoothly.

Thank your for your prompt reply.
Yes, it is in the class path.
It is in the same folder and I am using the following command to compile:
javac JakartaFtpWrapper.java JakartaWrapperTest.java -cp commons-net-ftp-2.0.jar

I am not using an IDE. I am trying to run it from command line.

I assume you've a folder,say test, in which you've two java files and one jar file. right?

I don't see any problem with the javac command. I've successfully compiled the java source files.

Can you run it as well?
When I run it I get NoClassDefFoundErrorr.

It says:

Exception in thread main java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient

I assumed that this is happening because of the error I get during compilation.

@ryy705
Now when I run javac -help I get the following message:-

stephen@stephen-desktop:~$ javac -help
Eclipse Java Compiler 0.894_R34x, 3.4.2 release
Copyright IBM Corp 2000, 2008. All rights reserved.

Usage: <options> <source files | directories>

Although I use the Eclipse Java compiler, but then too the usage should be the same even with the Sun JDK.
Now if you notice the above usage information properly, you need to specify your options before you specify your source files to compile, So you need to specify your CLASS path information (using the -cp option) before you specify the source files to compile, So instead of

javac JakartaFtpWrapper.java JakartaWrapperTest.java -cp commons-net-ftp-2.0.jar

try running this :-

javac -cp commons-net-ftp-2.0.jar JakartaFtpWrapper.java JakartaWrapperTest.java

And check if your sources compile.
Also while running run as :-

java -cp commons-net-ftp-2.0.jar:. <fully-qualified-name-of-main-class>

If on windows replace the ":" with ";" and do not forget the "." after it, it tells the JVM to search for the Main class in your current working directory. Hope it helps

This how I finally made it work:
First I commented out first line in JakartaWrapperTest.java. Which was:

import JakartaFtpWrapper;

Then I did the following(order doesn't seem to matter with option/source):
javac JakartaFtpWrapper.java JakartaWrapperTest.java -cp commons-net-ftp-2.0.jar

Then I did the following to run it:
javac -cp commons-net-ftp-2.0.jar JakartaFtpWrapper.java JakartaWrapperTest.java

Many thanks for this.

This question has already been answered. Start a new discussion instead.