javac question

Look at this.

c:\javactest contains only a directory called “src”

c:\javactest\src contains only a valid Test.java source file.

Now, why can’t I compile with

c:\javactest>javac -sourcepath src Test.java

(It works with c:\javatest\source>javac Test.java)

Aha! I logged a bug against this with Sun, and they accepted it IIRC only to tell me I was (basically) being annoying (and I kind of see their point) - IIRC (I’ll need to check what happened, actually).

My bug/RFE basically goes:

"sourcepath is one of the worst named flags ever: it doesn’t mean what it says, it actually means something different.

Worse, the documentation that comes with java 1.4.x provides a description that is incorrect - it describes something different to what is implemented because it omits a crucial sub-clause.

Please either change the docs, or even better rename the flag and also add a flag that really does mean “-sourcepath” because I actually need one!"

(My reasons for “needing” this flag are unusual, and to do with running javac in an environment where it is a very bad thing to list the contents of the current working directory, which - unfortunately - javac is hard-coded to do in it’s search for sources; I wanted it to use sourcepath to force it to look in a sub-dir ONLY, and not list the CWD, which incurs a massive performance penalty)

If you want to know more, I suggest you get a JDC ID (sorry - I hate the fact you need to do this, but it is free), go to Sun’s Bug Parade (google for it), do a search for bugs to do with sourcepath, and read the bug and the comments.

PS: Sorry, the short answer (appropriate for a newbie) is:

Sourcepath does NOT mean sourcepath.

It actually means (this is/was not documented by Sun) “the path where source files are loaded from ONLY when they are needed for recompilation of external classes referenced by the main source (which, because sourcepath doesn’t do what you think it does, can ONLY be compiled from the current working directory) which javac cannot find class files for, and so has decided to automatically compile from source in order to work out if the source code you are asking it to compile actually compiles”. Phew.

In other words, the flag ought to be:

-secondarysourcepath

or

-externalsourcepath

or something like that.

wow, blah3 is right… that is really stupid…

anyway, if you still want to compile sources that arent in your current directory, you can do this:

c:\javactest>javac src\Test.java

which is especially helpful if you’re compiling entire packages:

c:\javactest>javac src*.java

only problem with the first way right there is if that Test.java is using another class located in that directory, it won’t compile unless you do:

c:\javactest>javac -classpath src src\Test.java

…that’s another annoying thing about javac. Unlike its little brother java.exe, it doesn’t have the handy -cp flag… :-/

[quote][…]
only problem with the first way right there is if that Test.java is using another class located in that directory, it won’t compile unless you do:

c:\javactest>javac -classpath src src\Test.java
[…]
[/quote]
I’d never had to do that ???

I hafta do it with my 1.4.0 compiler :frowning:
Observe:


C:\Java\JunkBox>javac rpg\RPG.java
rpg\RPG.java:6: cannot resolve symbol
symbol  : class Test
location: class RPG
        Test test;
        ^
rpg\RPG.java:7: cannot resolve symbol
symbol  : class Surface
location: class RPG
        Surface surface;

but… with -classpath:


C:\Java\JunkBox>javac -classpath rpg rpg\RPG.java

C:\Java\JunkBox>

strange…

Ah… uhm… it’s because it doesn’t match the packaging, does it?

So if Test would be in the package rgb, javac would find it.

that’s probably true, I just dont usually mess with packages if all the classes are in one dir ::slight_smile:

C:\Java\JunkBox>cd rpg
C:\Java\JunkBox\rpg>javac RPG.java

should do the trick then :wink:

lol well YEAH we all know that, the point was to compile from a different directory than the classes like the OP wanted :stuck_out_tongue:

Hehe. Sorry :stuck_out_tongue:

I just enjoy being silly a bit too much :wink: