Possible Duplicate:
Java: How can I compile an entire directory structure of code?
In the javac command line, how to compile whole source dir with wildcard ?
javac src\com\mq\Main.java
changed to
javac src\*
can we do this ?
Thanks
Possible Duplicate:
Java: How can I compile an entire directory structure of code?
In the javac command line, how to compile whole source dir with wildcard ?
javac src\com\mq\Main.java
changed to
javac src\*
can we do this ?
Thanks
Just use a wildcard :
javac src\com\mq\*.java
You can use the @args technique, as defines in the javac documentation. It's a file containing the paths of the classes to compile.
If you use a linux/unix system, it's easy to create such a file :
find . -iname *.java > files.txt
javac @files.txt
It works recursively, just launch it at the root of your source directory.
Short answer: no
Longer answer: maybe
The javac command will compile all the files you list on the command line. If, using wildcards, you can create a list of all files in your src tree on the javac command line, the it will compile all of them.
On UNIX you can do something like this:
find src -type f -name "*.java" -print | xargs javac
One of the answers to the question of which this question is a duplicate (Java: How can I compile an entire directory structure of code ? from the Chip McCormick comment) demonstrates a find that uses the -exec parameter. For a large number of .java files that technique is better. For a small number of .java files I believe the one I show is effectively the same as the technique with the -exec parameter.
Have you considered using Ant? It makes this kind of thing much simpler. See: http://ant.apache.org/manual/Tasks/javac.html#srcdirnote
You just point it to the top level of your source tree, then you can selectively exclude anything you don't want to compile. You can also get more complicated if you need to, but that handles most common needs.
use cd command to go to the directory containing source files. then issue the command
javac *.java
The "right way" to do this would be to use a build tool like Ant or Maven or an IDE, which does this automatically for you.
For example, in Ant, you would use this task in your compile target:
<javac srcdir="src"
encoding="UTF-8"
destdir="classes">
</javac>