Compiling Multiple Classes (Console) in Java

Just do

javac *.java

Or if you have separate source and binary folders:

mkdir bin
javac -d bin src/*.java

Or if you have multiple source folders:

mkdir bin
shopt -s globstar # requires bash 4
javac -d bin src/**/*.java

As others have said, some variation on javac *.java will do the trick. However, my suggestion is that you learn how to use a Java build tool:

  • The Apache Ant tool is the "moral equivalent" of the classic Make tool. You create an "build.xml" file containing the targets that you want to build in an OS independent fashion and the sequences of operations to be performed.

  • The Apache Maven tool is based on a different philosophy. Instead of saying how to build your code, you describe the code, its dependencies and the things that you want built. Maven takes care of the "how" of building ... plus lots more. This is more complicated in the short term, but (in my experience) it has lots of benefits in the long term.

Tags:

Java