1

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

Community
  • 1
  • 1
user595234
  • 6,007
  • 25
  • 77
  • 101

6 Answers6

4

Just use a wildcard :

javac src\com\mq\*.java
Olivier Croisier
  • 6,139
  • 25
  • 34
4

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.

Olivier Croisier
  • 6,139
  • 25
  • 34
2

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.

Community
  • 1
  • 1
DwB
  • 37,124
  • 11
  • 56
  • 82
0

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.

mindcrime
  • 657
  • 8
  • 23
-1

use cd command to go to the directory containing source files. then issue the command
javac *.java

ThunderDragon
  • 613
  • 3
  • 13
  • 31
-1

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>
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210