File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes classpath. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "classpath." Watch "classpath." New topic


smita mishra
Ranch Hand

Joined: May 18, 2006
Posts: 31
here is the directory structure:
C:\ dirA\dirB\dirC\
when i try to compile by using the command
1:-c:\javac -cp dirA\dirB\dirC\
it displays the error message
javac: no source files
but when i use this command
2:-c:\java -cp \dirA \dirA\dirB\dirC\
it compiles successfully. what is the difference between 1st command & 2nd command.

if I am inside dirA i.e c:\dirA>
what should I give as classpath variable to complie & execute
what is relative classpath i.e what is meaning of -cp dirB;dirB\dirC?
if i execute the command c:\dirA> javac -cp dirB;dirB\dirC\ error message is "javac: no source files is found ".
why did I get this error message when file is inside dirC.
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
c:\javac -cp dirA\dirB\dirC\

2:-c:\java -cp \dirA \dirA\dirB\dirC\

The above both statements do not execute on my machine (jdk 1.4) and the error is "invalid flag: -cp".

But instead of -cp if I -classpath flag is used then the error as stated by you no source files is thrown.

Here is the explanation:
In your first case : the classpath variable was set to dirA\dirB\dirC\ and you did not specify any source files after that to execute. Afte the classpath is set you need to specify the source files. Try this it will work

c:\javac -cp dirA\dirB\dirC\ dirA\dirB\dirC\

The first argument is for classpath and the second argument is the source file which when compiled using classpath dirA\dirB\dirC\

Comming to the second case which works : This is because now the classpath points to \dirA and the next argument is the source file that needs to be executed. The space between \dirA and \dirA\dirB\dirC\ acts as delimiter for the input arguments for the javac command.

If your in the same directory as the source files; you need not give classpath, just execute.

My feeling is that you have been confused with classpath and sourcepath.

check the javac help.

You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
I agree. Here's the link:
subject: classpath.
It's not a secret anymore!