javac and -sourcepath

Long time since I compiled my java-files manually to classes.

These are the classes:
my.stuff.City
my.stuff.Factory

In these files:
C:/somewhere/my/stuff/City.java
C:/somewhere/my/stuff/Factory.java

Now it’s dead-easy to compile this:
C:/somewhere/> javac my/stuff/City.java my/stuff/Factory.java

But here’s the catch, the current directory is NOT C:/somewhere, but it’s C:/

According to the javac-documentation I should do this:
C:/>javac -sourcepath C:/somewhere my/stuff/Factory.java

error: cannot read: my/stuff/Factory.java

Doesn’t work. I tried just about everything I could think of, but I only manage to compile it if the current-directory is the root of the package >:(

This is a documented feature, what am I doing wrong?

Are you sure you got dir name right? It sounds like a typo, like it should be C:/somewhere/my stuff/ … or C:/somewhere/my/stuff/ …
and if you are working in windows use backslashes.

EDIT: oh you listed where files are … then it’s just a missing slash in your source path argument

Me: " I tried just about everything I could think of, "

I’d suggest you try it for yourself, there is no way it works >:(

C:/>javac -sourcepath C:/somewhere somewhere/my/stuff/Factory.java

The path to the source files is relative to your current location, even though you specified the source path. However, if Factory.java imports some other classes, it will find the sources (because of -sourcepath).

Thanks!

Imagine java.exe worked like that :o

java -classpath myDirectory/workspace myDirectory/workspace/my.package.MyClass

I know how it works now, but it’s far from intuitive.

Heh, the only difference is that javac takes the path to the source files(s) as argument, java.exe takes the class name as argument, which kind of makes sense to me…
Your example is a mix of both and is just weird :slight_smile: