Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javac sourcepath classpath options

 
Swaminathan Raman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Swaminathan Raman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic