2

I have this java source file

C:\crp\dfdf\src\oata\HelloWorld.java

I can compile it

C:\crp\dfdf>javac -sourcepath c:\crp\dfdf -d build\classes src\oata\HelloWorld.j ava

into

C:\crp\dfdf\build\classes\oata\HelloWorld.class

But I notice that (keeping the same directory and keeping the same other parameters as above) then whatever the sourcepath is, it still works

C:\crp\dfdf>javac -sourcepath c:\sdklsdlewrrblahthisdirdoesnotexist -d build\classes src\oata\HelloWorld.java

C:\crp\dfdf>

And if I correct the sourcepath (so, back to c:\crp\dfdf\src) but move to a different directory, then it doesn't work

C:\>javac -sourcepath c:\crp\dfdf\src -d build\classes src\oata\HelloWorld.java
javac: file not found: src\oata\HelloWorld.java
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>

I thought maybe the path of the file specified appends to the sourcepath, but this doesn't work either

C:\>javac -sourcepath c:\crp\dfdf\src -d build\classes oata\HelloWorld.java
javac: file not found: oata\HelloWorld.java
Usage: javac <options> <source files>
use -help for a list of possible options

So i'm having trouble seeing how sourcepath is operating

1 Answer 1

3

The -sourcepath is used when other files that may need compiling as dependencies aren't located where you would expect under the current directory or in relation to the source path of the file you specified to compile. It's rarely used.

2
  • could you give a simple example? so a java file with a dependency such that -sourcepath would be used and makes a difference.. so I could see what it looks like? ta
    – barlop
    Aug 1, 2014 at 2:52
  • Looks like -cp / -classpath, does too pastebin.com/raw.php?i=wB17PFEM pastebin.com/raw.php?i=wB17PFEM
    – barlop
    Aug 4, 2014 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.