|
-
Jun 13th, 2005, 10:22 PM
#1
Thread Starter
Fanatic Member
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.
Last edited by nebulom; Jun 14th, 2005 at 04:43 AM.
-
Jun 14th, 2005, 03:26 AM
#2
Re: javac with -sourcepath switch
-sourcepath src
I also highly recommend Ant over any other build system for Java.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 14th, 2005, 03:36 AM
#3
Thread Starter
Fanatic Member
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.
Last edited by nebulom; Jun 14th, 2005 at 03:46 AM.
-
Jun 14th, 2005, 03:51 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 14th, 2005, 03:58 AM
#5
Thread Starter
Fanatic Member
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.
-
Jun 14th, 2005, 04:13 AM
#6
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 14th, 2005, 04:28 AM
#7
Thread Starter
Fanatic Member
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.
-
Jun 14th, 2005, 04:35 AM
#8
Re: javac with -sourcepath switch
I edited my post after actually trying out what I wrote.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|