5-Line-Replacement of Apache Ant

rm -rf build/
mkdir build
jars=$(find ./lib/ -iname "*.jar" | tr  '\n' ':')
find ./src -iname "*\.java" > files.txt
$JAVAC_CMD -d build/ -cp $jars @files.txt

Okay, it is a very very unfair blog title – only an eye catcher!

But now you can bookmark this useful code snippet to compile your project without installing ant or even an IDE.

… and you could say: “Hey man – this is not platform independent!”.
But then I would say: “Oh yes it is! For windows you should install cygwin of course!”

Keep smiling 😉

Update: on windows with cygwin you have to replace the colon : with a semicolon ;


6 thoughts on “5-Line-Replacement of Apache Ant

  1. Oh calm down – you should keep smiling as I said! Could you comment such statements? Why is this dumb?
    I know the header is a little bit provocating, but I don’t want to harm anybody 🙂
    I just want to show you how to compile a nontrivial project with alots of jars and java files without an IDE or ant.
    Do you know a better/shorter way?
    Another question could be: “Could you implement this in Java in less then 30 lines?”
    Please feel free to post the code!

  2. Well sometimes I’ll do

    find src -name ‘*.java’ -exec javac -cp $CLASSPATH {} \;


    jar cvf code.jar `find src -name ‘*class’`

  3. Good work! Ignore the “dumb” comment. Sometime it’s nice to see how things are done from different perspectives. Helps see the world in a new light. I like it too…

Comments are closed.