1

Based on suggestions from my previous question on programmers.SE, I have split my current project into three subdirectories (swing, common, and android) and created separate Ant scripts in each one. Now I easily created NetBeans projects in the swing and common and was able to set the proper dependencies to compile the Swing app. Then when I go to use classes from the "common" project, I realize that I need to have another Ant script for the Android build process.

So now I have four Ant scripts used to build different parts of my project, along with separate src, test, and other supporting directories for each project. The first problem I encountered is that both NetBeans and the ant script for my "android" project want to use "build.xml" in my "common" project for various build tasks, some of which have name clashes. I decided I want to consolidate all of these projects back into one directory with src, test, etc. subdirectories. The source code is already organized into separate packages for each of the projects and I thought this would make it simpler since I can have a single Ant build script with separate tragets for the Swing and Android builds.

Now the problem I am running into is that when I try to build the "android" project, it wants to build all the Swing classes as well. This brings up a lot of compiler errors. I have even modified the <javac> task in an attempt to exclude the bbct.swing package hierarchy from compileing:

        <javac encoding="${java.encoding}"
                source="${java.source}" target="${java.target}"
                debug="true" extdirs="" includeantruntime="false"
                destdir="${out.classes.absolute.dir}"
                bootclasspathref="project.target.class.path"
                verbose="${verbose}"
                classpathref="project.javac.classpath"
                fork="${need.javac.fork}"
                excludes="${source.dir}/bbct/swing/**"> <------- here
            <src path="${source.absolute.dir}" />
            <src path="${gen.absolute.dir}" />
            <compilerarg line="${java.compilerargs}" />
        </javac>

Ant still insists on compiling my classes which use Swing, though.

So I have two questions:

  1. What is the best way to organize this project? Would you suggest one of the two that I have tried or something else entirely?

  2. If I stick with my most recent solution, how do I make javac ignore the Swing-based source files in my project?

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

1 Answers1

1

Between How to exclude a source package using javac in Ant? and How can I exclude sources in a javac task in ant?, I found a solution using an <exclude> elements, rather than the excludes attribute. Here is the relevant <javac> task:

        <javac encoding="${java.encoding}"
               source="${java.source}" target="${java.target}"
               debug="true" extdirs="" includeantruntime="false"
               destdir="${out.classes.absolute.dir}"
               bootclasspathref="project.target.class.path"
               verbose="${verbose}"
               classpathref="project.javac.classpath"
               fork="${need.javac.fork}">
            <src path="${source.absolute.dir}" />
            <exclude name="bbct/swing/**" />
            <src path="${gen.absolute.dir}" />
            <compilerarg line="${java.compilerargs}" />
        </javac>

Addendum:

I suspect that the core of this solution lies in using a path relative to the source attribute or the <src> element. This means that an excludes element should work just as well using a relative path. I haven't tested this yet, though.

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268