Vytas P.
Vytas P.

Reputation: 983

Building Java package (javac to all files)

How to compile all files in directory to *.class files?

Upvotes: 14

Views: 35692

Answers (3)

Kipton Barros
Kipton Barros

Reputation: 21112

Yet another way using "find" on UNIX is described here:

http://stas-blogspot.blogspot.com/2010/01/compile-recursively-with-javac.html

The following two commands will compile all .java files contained within the directory ./src and its subdirectories:

find ./src -name *.java > sources_list.txt
javac -classpath "${CLASSPATH}" @sources_list.txt

First, find generates sources_list.txt, a file that contains the paths to the Java source files. Next, javac compiles all these sources using the syntax @sources_list.txt.

Upvotes: 10

Kilian Foth
Kilian Foth

Reputation: 14396

Here's a code fragment that I use to build an entire project where, as usual, source files are in a deeply nested hierarchy and there are many .jar files that must go into the classpath (requires UNIX utilities):

CLASSPATH=
for x in $(find | grep jar$); do CLASSPATH="$CLASSPATH:$x"; done
SRC=$(find | grep java$)
javac -cp "$CLASSPATH" $SRC

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1503839

Well, this seems pretty obvious, so I may be missing something

javac *.java

(With appropriate library references etc.)

Or perhaps:

javac -d bin *.java

to javac create the right directory structure for the output.

Were you looking for something more sophisticated? If so, could you give more details (and also which platform you're on)?

Upvotes: 25

Related Questions