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 5974747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:59:08+00:00 2026-05-22T20:59:08+00:00

I’m trying to run some tests in Ant presently using JUnit, and all of

  • 0

I’m trying to run some tests in Ant presently using JUnit, and all of my tests are failing with the following stacktrace:

java.lang.ClassNotFoundException: com.mypackage.MyTestCase

It doesn’t make too much sense to me. I’m first compiling my test cases using <javac>, then directly running the <junit> task to run the tests. My buildfile looks like this:

<target name="compile.webapp.tests" depends="compile.webapp">
    <javac srcdir="${test.java.src.dir}"
            destdir="${test.java.bin.dir}">
        <classpath>
            <filelist>
                <file name="${red5.home}/red5.jar"/>
                <file name="${red5.home}/boot.jar"/>
                <file name="${bin.dir}/${ant.project.name}.jar"/>
            </filelist>
            <fileset dir="${red5.lib.dir}" includes="**/*"/>
            <fileset dir="${main.java.lib.dir}" includes="**/*"/>
            <fileset dir="${test.java.lib.dir}" includes="**/*"/>
        </classpath>
    </javac>
</target>

<target name="run.webapp.tests" depends="compile.webapp.tests">
    <junit printsummary="true">
        <classpath>
            <filelist>
                <file name="${red5.home}/red5.jar"/>
                <file name="${red5.home}/boot.jar"/>
                <file name="${bin.dir}/${ant.project.name}.jar"/>
            </filelist>
            <fileset dir="${red5.lib.dir}" includes="**/*.jar"/>
            <fileset dir="${main.java.lib.dir}" includes="**/*.jar"/>
            <fileset dir="${test.java.lib.dir}" includes="**/*.jar"/>
            <fileset dir="${test.java.bin.dir}" includes="**/*.class"/>
        </classpath>
        
        <formatter type="xml"/>
        
        <batchtest todir="${test.java.output.dir}">
            <fileset dir="${test.java.bin.dir}" includes="**/*TestCase*"/>
        </batchtest>
    </junit>
    
    <junitreport>
        <fileset dir="${test.java.output.dir}" includes="**/*"/>
        <report todir="${test.java.report.dir}"/>
    </junitreport>
</target>

This is really weird, I can’t seem to fix this. Is there something I’m doing wrong here?
My project’s directory layout looks somewhat like this:

${basedir}/src/test/java # this is "test.java.src.dir"
${basedir}/build/test/java # this is "test.java.bin.dir"
${basedir}/lib/main/java # this is "main.java.lib.dir"
${basedir}/lib/test/java # this is "test.java.lib.dir"
${basedir}/build/test/junit # this is "test.java.output.dir"

My complete buildfile is available here: http://pastebin.com/SVnciGKR
My properties file is available here: http://pastebin.com/9LCtNQUq


UPDATE

By modifying my targets to look like below, I was able to get things working. Unfortunately, I have to manually embed ant-junit.jar and junit.jar into my repository, but it works, so I guess this solves it. If anyone can help me get rid of the need to embed ant-junit.jar and junit.jar, I’d really appreciate it:

<path id="webapp.tests.path" >
    <pathelement location="${red5.home}/red5.jar"/>
    <pathelement location="${red5.home}/boot.jar"/>
    <pathelement location="${bin.dir}/${ant.project.name}.jar"/>
    <pathelement path="${red5.lib.dir}"/>
    <pathelement path="${main.java.lib.dir}"/>
    <pathelement path="${test.java.lib.dir}"/>
</path>

<target name="compile.webapp.tests" depends="compile.webapp">
    <javac srcdir="${test.java.src.dir}"
            destdir="${test.java.bin.dir}">
        <classpath refid="webapp.tests.path"/>
    </javac>
</target>

<target name="run.webapp.tests" depends="compile.webapp.tests">     
    <junit printsummary="true">
        <classpath>
            <path refid="webapp.tests.path"/>
            <pathelement location="${test.lib.dir}/ant/ant-junit.jar"/>
            <pathelement location="${test.lib.dir}/ant/junit-4.8.2.jar"/>
            <pathelement path="${test.java.bin.dir}"/>
        </classpath>
        
        <formatter type="xml"/>
        
        <batchtest todir="${test.java.output.dir}">
            <fileset dir="${test.java.bin.dir}" includes="**/*TestCase*"/>
        </batchtest>
    </junit>
    
    <junitreport todir="${test.java.report.dir}">
        <fileset dir="${test.java.output.dir}" includes="**/*"/>
        <report todir="${test.java.report.dir}"/>
    </junitreport>
    
    <delete file="${test.java.report.dir}/TESTS-TestSuites.xml"/>
</target>

If I don’t include the jars in the classpath, I get errors telling me that junit.jar must be on the classpath in order to run the <junit> task. Weird, huh?

  • 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-22T20:59:08+00:00Added an answer on May 22, 2026 at 8:59 pm

    According to the ANT documentation for JUnit Task you have to do one of the following options to get junit tests to run as there is a dependency on an the junit.jar which is external to ANT:

    Note: You must have junit.jar
    available. You can do one of:

    1. Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
    2. Do not put either in ANT_HOME/lib, and instead include their locations in
      your CLASSPATH environment variable.
    3. Add both JARs to your classpath using -lib.
    4. Specify the locations of both JARs using a element in a
      in the build file.
    5. Leave ant-junit.jar in its default location in ANT_HOME/lib but include
      junit.jar in the passed to
      <junit>. (since Ant 1.7)

    I have verified that #1, putting junit.jar in ANT_HOME\lib worked (ant-junit.jar was already there, ANT 1.8.0) and I did not need to specify a junit.jar in the classpath for the JUNIT tag. Essentially you took option #5.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.