aspose file tools*
The moose likes Beginning Java and the fly likes javac sourcepath classpath options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javac sourcepath classpath options" Watch "javac sourcepath classpath options" New topic
Author

javac sourcepath classpath options

Swaminathan Raman
Greenhorn

Joined: Mar 07, 2008
Posts: 3
Hi ,
This is my first post!

I am having trouble using the sourcepath and classpath options in javac.

HelloWorld.java is in C:\Java.
If I go to C:\Java and use javac it compiles fine.

I am currently in the D:\Documents and Settings\Administrator directory. If I use
javac -classpath C:\Java HelloWorld.java

i am getting file not found : HelloWorld.java.

the same happens when I try javac -sourcepath C:\Java HelloWorld.java

but things work fine if I use the full path C:\Java\HelloWorld.java.

So, why isnt the classpath option working as it is supposed to?

thanks
Kevin
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

The classpath tells Java where to find Java class files. It does not tell Java where to find source files.

I'm not very familiar with the sourcepath option, but my understanding is that it's for specifying the location of .java source files that your main source file is dependent on -- not the location of the main file itself.

Does that make sense?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Swaminathan Raman
Greenhorn

Joined: Mar 07, 2008
Posts: 3
yes...its kinda makes sense. So what would one do if the main source file is in a different directory?

I understand that it is easy to go to the source file directory in my case. But then there could be circumstances where one might want to compile source files in a different directory.

Is there a way out?
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I have been having exactly that problem, last night I started picking up builds even on files that were on a different root. That was because I had used settings/control panel/system/advanced/environment variables to set a long string containing every dir I could think of and then later was trying to work on a temporary version without disturbing the main build.

See: @argfiles which is likely more useful. This allows fast access to a configuration file that is stored with the sources.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac sourcepath classpath options