Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3692046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:13:02+00:00 2026-05-19T04:13:02+00:00

Currently I use an IDE for all my builds and unit tests. Now I

  • 0

Currently I use an IDE for all my builds and unit tests. Now I have a need to use ant. I found a few simple ant build.xml scripts but they didn’t support a separate Junit test/ dir. My projects are structured as follows:

src/
  com/foo/
  com/bar/

test/ -- Mirror of src/, with all *Test.java files.
  com/foo/ 
  com/bar/

lib/  -- All Java libs, including junit 4.

How can a construct a small ant script that builds my src/ and test/ Java classes then runs all my JUnit tests?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:13:03+00:00Added an answer on May 19, 2026 at 4:13 am

    I define <path> elements for each target.

    This is an excerpt from my build file, you’ll have to adapt some paths and properties, but you can get the idea:

    <path id="src.path">    
        <pathelement path="src/"/>
    </path>
    
    <path id="compile.path">
        <path refid="src.path"/>
        <fileset dir="lib/">
            <include name="**/*.jar"/>
        </fileset>
    </path>
    
    <path id="unit.test.path">
        <path refid="compile.path"/>
        <pathelement path="test/"/>
    </path>
    
    <target name="compile">
        <javac destdir="bin">
            <src path="src"/>
            <classpath refid="compile.path"/>
        </javac>
    </target>
    
    <target name="compileUnitTests" depends="compile">
        <javac srcdir="test/" destdir="bin">
            <classpath refid="unit.test.path"/>
        </javac>
    </target>
    
    <target name="runUnitTests" depends="compileUnitTests">
        <junit printsummary="yes" haltonfailure="no">
        <jvmarg value="-Dfile.encoding=UTF-8"/>
            <classpath refid="unit.test.path"/>
    
            <formatter type="xml"/>
    
            <batchtest fork="yes" todir="${this.report}">
                <fileset dir="test">
                    <include name="${test.pattern}"/>
                    <exclude name="**/AllTests.class"/>
                    <exclude name="**/*$*.class"/>
                </fileset>
            </batchtest>
        </junit>
    </target>
    

    And if you need to refine this to your needs, as cotton.m says, go read the ant task docs. Using ant with your specific directory structure does require some knowledge of the tool, don’t expect you’ll easily find ready-made examples that just work with your exact requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This concerns the state of Struts2 framework tooling, although currently I use no IDE
I work in at small .net shop where we currently build all our solutions
Here's the situation that I'm working with: Build tests in Selenium Get all the
I've used various IDE's (Eclipse, NetBeans, Intellij IDEA) and although all of them have
Anyy recommendations on a IDE to use for the MAC? I currently use TextMate
Question about the m2 eclipse plugin. Currently I have Eclipse Java EE IDE for
I currently use Berkeley DBs fronted by a Java server for a high-performance disk-backed
I currently use: BufferedReader input = new BufferedReader(new FileReader(filename)); Is there a faster way?
I currently use the free obfuscation tool that ships with VS and it does
I currently use a System.IO.FileSystemWatcher as part of a roll your own message queue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.