javac with -sourcepath switch
I'm a little bit of lost with the -sourcepath switch. I'm structuring my project like this
Code:
classes
+ class destination
docs
+ documentation
src
+ java files
make.bat
And my make.bat is
Code:
javac -d classes -sourcepath src/*.java
javadoc -d doc -sourcepath src/*.java
But it only gets the last file. Say I have dtgen.java and Server.java, it only gets Server.java to be compiled and the class gets to classes and Server.html to doc+generated htmls.
What should I put after -sourcepath switch? Right now, I ended up to putting make.bat to src folder having a content like
Code:
javac -d ../classes *.java
javadoc -d ../doc *.java
Thanks in advance.
Re: javac with -sourcepath switch
-sourcepath src
I also highly recommend Ant over any other build system for Java.
Re: javac with -sourcepath switch
Thanks, CB. I'll be learning Ant.
-sourcepath src BTW, doesn't do compiling. It says javac: no source files. Nevermind anyway, have to find good build system.
Re: javac with -sourcepath switch
The -sourcepath switch doesn't specify which files to compile. It merely tells javac where to look for source files that the explicitely specified sources depend on.
Re: javac with -sourcepath switch
javac -d classes -sourcepath src
Does it suppose to compile all the .java in the src folder? It just displays the Usage: javac <options> <source files> after displaying javac: no source files.
Re: javac with -sourcepath switch
No, it does nothing, because you specified no source files. But consider this:
Code:
// Class1.java
public class Class1
{
}
// Class2.java
public class Class2 extends Class1
{
}
Clearly, Class2.java depends on Class1.java being available. Let's assume you have this directory structure:
Code:
PROJECT_ROOT
-> classes (compiled sources)
-> docs (documentation)
-> src (source code)
-> Class1.java
-> Class2.java
From the PROJECT_ROOT, you could now type
Code:
javac -d classes src/Class2.java
The compilation will fail:
Code:
src/Class2.java:3: cannot find symbol
symbol: class Class1
public class Class2 extends Class1
^
1 error
The compiler can't find Class1.java.
This command will succceed:
Code:
javac -d classes -sourcepath src src/Class2.java
Now the compiler knows where to look for dependencies. It will compile both Class1.java and Class2.java.
You should also add the -classpath:
Code:
javac -d classes -classpath classes -sourcepath src Class2.java
This way, the compiler will find Class1.class if it exists, and not compile it again.
Re: javac with -sourcepath switch
Assuming I have Class2.java, it says error: cannot read: Class2.java. I don't what did I miss but I've compiled it by javac -d classes -classpath classes -sourcepath src dtgen.java and I'm pretty sure, there is a dtgen.java in the src folder.
error: cannot read: dtgen.java
Thanks for being patient CB. I think I just have to learn Ant from now on. Again, thanks.
Re: javac with -sourcepath switch
I edited my post after actually trying out what I wrote.