

Compiling java with ant command line code#
Here's the source code for that part of my build process:Īs you can see, this segment of code builds a variable named class.path based on all the jar and zip files that are in my project's lib folder. Because Ant is a command-line build tool, it is possible to execute only a subset of the target steps in the Ant file. For the purpose of completeness, I thought I better include the target I created that builds this classpath variable. I mentioned that earlier in my build script I created the variable named class.path. (This is a collection of images that are used by my application.) When compiling, I set the classpath using the class.path variable, which I created earlier in my build script.Īfter the javac task executes successfully, I copy a bunch of image files from the src directory structure to the classes folder structure. By convention, I named all my unit test classes this way, so I am able to exclude them in the compiling process. This task compiles all the files found in the src directory, excluding all files matching the naming patter Test*.java.

The first part of the script runs the Ant javac task. Here's a brief description of what this Ant target does: Here's the source code for my Ant compile target: This particular script happened to be used for building a Swing application, but it can really be used to build any Java application, command-line based or other.
Compiling java with ant command line how to#
While I'm digging around through Ant build scripts today, here's a sample Ant target I created that demonstrates how to compile a Java program, while also showing a few other things, including how to exclude your JUnit tests during the compile process.
