David Castle
David Castle

Reputation: 149

Using Ant to compile a project based on a single file and it's dependencies

Currently, when building our project we use:

javac <various command line options> C:\project\CompilationHelper.java

The CompilationHelper class then references our main files and through a chain of dependencies everything we need gets compiled and nothing more. The class directory is then jar'ed.

I've started using ant and noticed that by just building our source directory we get a larger .jar file than normal.

I realise that the best solution is to find all the unused .java files and remove them but we actually have one "main" project and one "child" project within it which uses a lot of the components of the main one and separating them is unfeasable at the moment.

Is there a way to tell ant to compile one file and all it's dependencies rather than a directory?

Many thanks in advance,

Dave

Upvotes: 2

Views: 3476

Answers (1)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74800

You can use your CompilationHelper method in ant, too. Just give the CompilationHelper.java to your javac task, instead the whole source directory.

Here is an example:

<javac srcdir="src"
       destdir="classes">
  <include name="CompilationHelper.java" />
</javac>

If all the source files are (according to their package structure) below src, and a package-less class CompilationHelper in this directory, it should work.

Upvotes: 3

Related Questions