I would like to be able to compile all java files in all subdirectories from what I'm working in.
I know how to compile all java files in the same directory, but how do I do it for all subdirectories (and subdirectories of those, etc.)?
I would like to be able to compile all java files in all subdirectories from what I'm working in.
I know how to compile all java files in the same directory, but how do I do it for all subdirectories (and subdirectories of those, etc.)?
try using ant script, give the base dir of source file to srcdir
<target name="compile">
<javac srcdir="src" destdir="build/classes"/>
</target>
There are multiple ways of doing this.
Using Javac
You have to know all the directories beforehand, or be able to use wildcard. The command goes this way:
javac dir1/*.java dir2/*.java dir3/dir4/*.java dir3/dir5/*.java dir6/*src/*.java
(OR)
If you can create a list of all the *.java files in your project, it's easy:
Linux
$ find -name "*.java" > sources.txt
$ javac @sources.txt
Windows
> dir /s /B *.java > sources.txt
> javac @sources.txt
Using a build tool
It is always better to use a tool that was designed to build software.
Using Ant
If you create a simple build.xml file that describes how to build the software:
<project default="compile">
<target name="compile">
<mkdir dir="bin"/>
<javac srcdir="src" destdir="bin"/>
</target>
</project>
you can compile the whole software by running the following command:
$ ant
Now that you know all the ways (at least, most ways), the choice is yours! :-)