This discussion is archived
6 Replies Latest reply: Sep 5, 2008 5:38 AM by 656336 RSS

BUILD FAILED: problem with junit

843789 Newbie
Currently Being Moderated
Hi, I'm taking the CDJ-310A - Developing Applications for the J2EE Platform course and have run into a problem when issuing a call to asant. When I run asant test the message it gives is "Ant could not find the task or a class this task relies upon.".The errors I get refer to the junit package.

I've check the CLASSPATH and it seams ok:

D:\labs\FJ310\bankproject>javap junit.framework.TestCase
Compiled from "TestCase.java"
public abstract class junit.framework.TestCase extends junit.framework.Assert im
plements junit.framework.Test{
public junit.framework.TestCase();
public junit.framework.TestCase(java.lang.String);
public int countTestCases();
protected junit.framework.TestResult createResult();
public junit.framework.TestResult run();
public void run(junit.framework.TestResult);
public void runBare() throws java.lang.Throwable;
protected void runTest() throws java.lang.Throwable;
protected void setUp() throws java.lang.Exception;
protected void tearDown() throws java.lang.Exception;
public java.lang.String toString();
public java.lang.String getName();
public void setName(java.lang.String);
}


D:\labs\FJ310\bankproject>javap junit.textui.TestRunner
Compiled from "TestRunner.java"
public class junit.textui.TestRunner extends junit.runner.BaseTestRunner{
public static final int SUCCESS_EXIT;
public static final int FAILURE_EXIT;
public static final int EXCEPTION_EXIT;
public junit.textui.TestRunner();
public junit.textui.TestRunner(java.io.PrintStream);
public junit.textui.TestRunner(junit.textui.ResultPrinter);
public static void run(java.lang.Class);
public static junit.framework.TestResult run(junit.framework.Test);
public static void runAndWait(junit.framework.Test);
public void testFailed(int, junit.framework.Test, java.lang.Throwable);
public void testStarted(java.lang.String);
public void testEnded(java.lang.String);
protected junit.framework.TestResult createTestResult();
public junit.framework.TestResult doRun(junit.framework.Test);
public junit.framework.TestResult doRun(junit.framework.Test, boolean);
protected void pause(boolean);
public static void main(java.lang.String[]);
public junit.framework.TestResult start(java.lang.String[]) throws jav
a.lang.Exception;
protected junit.framework.TestResult runSingleMethod(java.lang.String, java.
lang.String, boolean) throws java.lang.Exception;
protected void runFailed(java.lang.String);
public void setPrinter(junit.textui.ResultPrinter);
}

But still these errors still are produced:

D:\labs\FJ310\bankproject>asant clean
Buildfile: build.xml

clean:
[delete] Deleting directory D:\labs\FJ310\bankproject\build
[delete] Deleting directory D:\labs\FJ310\bankproject\jar

BUILD SUCCESSFUL
Total time: 0 seconds
D:\labs\FJ310\bankproject>asant
Buildfile: build.xml

prepare:
[mkdir] Created dir: D:\labs\FJ310\bankproject\build
[mkdir] Created dir: D:\labs\FJ310\bankproject\jar

compile:
[javac] Compiling 6 source files to D:\labs\FJ310\bankproject\build
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:9: package junit
.framework does not exist
[javac] import junit.framework.*;
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:11: cannot find
symbol
[javac] symbol: class TestCase
[javac] public class BankMgrTest extends TestCase {
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:15: cannot find
symbol
[javac] symbol : class Test
[javac] location: class bank.BankMgrTest
[javac] public static Test suite() {
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:16: cannot find
symbol
[javac] symbol : class TestSuite
[javac] location: class bank.BankMgrTest
[javac] return new TestSuite(BankMgrTest.class);
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:20: package juni
t.textui does not exist
[javac] junit.textui.TestRunner.run(suite());
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:39: cannot find
symbol
[javac] symbol : method assertEquals(java.lang.String,java.lang.String)
[javac] location: class bank.BankMgrTest
[javac] assertEquals("Fred", data.getFirstname());
[javac] ^
[javac] D:\labs\FJ310\bankproject\src\bank\BankMgrTest.java:40: cannot find
symbol
[javac] symbol : method assertEquals(java.lang.String,java.lang.String)
[javac] location: class bank.BankMgrTest
[javac] assertEquals("Flintstone", data.getLastname());
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 7 errors

BUILD FAILED
D:\labs\FJ310\bankproject\build.xml:14: Compile failed; see the compiler error o
utput for details.

Total time: 4 seconds

Any help solving these errors would be highly appreciated. I'm stuck right now. Thanks!
  • 1. Re: BUILD FAILED: problem with junit
    843789 Newbie
    Currently Being Moderated
    It looks like you need to add the junit jar file to your classpath. It's probably called junit-4.4.jar
  • 2. Re: BUILD FAILED: problem with junit
    843789 Newbie
    Currently Being Moderated
    Thanks for your reply.

    However, I think that I have the junit jar file in my CLASSPATH.
    The CLASSPATH is set as:
    CLASSPATH = .;C:\Sun\SDK\lib\javaee.jar;D:\junit.4.4\junit-4.4.jar;D:\junit.4.4;C:\Program Files\Java\jre1.6.0_04\lib\ext\QTJava.zip.

    The file properties of the junit-4.4.jar file I am trying to reference are set in CLASSPATH as: D:\junit.4.4\junit-4.4.jar. Does this look right?

    Thanks.
  • 3. Re: BUILD FAILED: problem with junit
    843789 Newbie
    Currently Being Moderated
    That classpath environment variable may not actually be used. Mine is never set, I believe that is the best practice. When I use ANT I usually have something that looks like this early in the build.xml:
         <path id="class.path">
              <pathelement location="${dest}" />
              <fileset dir="${lib}" includes="*.jar" />
              <fileset dir="${spring2.lib}/dom4j" includes="*.jar" />
              <fileset dir="${spring2.lib}/log4j" includes="*.jar" />     
              <pathelement location="${spring2.lib}/hibernate/hibernate3.jar" />
              <pathelement location="${spring2.lib}/junit/junit-4.4.jar" />
              <pathelement location="${spring2.lib}/jakarta-commons/commons-logging.jar" />
         </path>
    I'm sure your's won't be this complicated, but that example shows most of the possibilities, including single elements and including everything that matches some pattern.
  • 4. Re: BUILD FAILED: problem with junit
    843789 Newbie
    Currently Being Moderated
    Hi, your suggestion did not work for me.

    But I did find a solution -- I used the -lib flag like : ant -lib D:\junit.4.4\junit-4.4.jar

    Thanks for the help!
  • 5. Re: BUILD FAILED: problem with junit
    843789 Newbie
    Currently Being Moderated
    spencer_nyc wrote:
    Hi, your suggestion did not work for me.

    But I did find a solution -- I used the -lib flag like : ant -lib D:\junit.4.4\junit-4.4.jar

    Thanks for the help!
    The -lib will work if the path isn't large and doesn't have complex includes. Did you include the class.path reference in you compile task? You would need something like
    <javac classpathref="class.path" destdir="${dest}/classes" srcdir="${src}"  debug="true" />
  • 6. Re: BUILD FAILED: problem with junit
    656336 Newbie
    Currently Being Moderated
    i have this problem too. and i added in CLASSPATH the path for junit.jar file. but still does not work
    my build.xml file :
    <project name="bankproject" default="deploy" basedir=".">
    
      <property environment="env"/>
      <property name="src.dir"     value="${basedir}/src"/>
      <property name="build.dir"   value="${basedir}/build"/>
      <property name="jar.dir"     value="${basedir}/jar"/>
    
      <target name="prepare">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${jar.dir}"/>
      </target>
    
      <target name="compile" depends="prepare" >
        <javac destdir="${build.dir}">
          <src path="${src.dir}"/>
        </javac>
      </target>
    
      <target name="package-bankmgr" depends="compile">
        <delete file="${jar.dir}/BankEJBModule.jar"/>
        <copy file="dd/bank-ejb-jar.xml" tofile="${build.dir}/ejb-jar.xml" overwrite="true"/>
        <copy file="dd/bank-sun-ejb-jar.xml" tofile="${build.dir}/sun-ejb-jar.xml" overwrite="true"/>
    
        <jar jarfile="${jar.dir}/BankEJBModule.jar">
          <metainf dir="${build.dir}" includes="ejb-jar.xml,sun-ejb-jar.xml" />
          <fileset dir="${build.dir}">
            <include name="bank/**" />
            <exclude name="bank/BankMgrTest.class" />
            <exclude name="bank/CustomerTest.class" />
          </fileset>
        </jar>
      </target>
    
      <target name="package-ejbs" depends="package-bankmgr" />
    
      <target name="package-client" depends="compile">
        <delete file="${jar.dir}/ClientModule.jar"/>
        <copy file="dd/bank-application-client.xml" tofile="${build.dir}/application-client.xml" overwrite="true"/>
        <copy file="dd/bank-sun-application-client.xml" tofile="${build.dir}/sun-application-client.xml" overwrite="true"/>
    
        <jar jarfile="${jar.dir}/ClientModule.jar">
          <manifest>
             <attribute name="Main-Class" value="bank.MessageClient" />
         </manifest>
          <metainf dir="${build.dir}" includes="application-client.xml,sun-application-client.xml" />
          <fileset dir="${build.dir}">
            <include name="bank/MessageClient.class" />
          </fileset>
        </jar>
      </target>
      
      <target name="assemble-app" depends="package-ejbs,package-client">
        <delete file="${jar.dir}/BankApplication.ear"/>
        <copy file="dd/bank-application.xml" tofile="${build.dir}/application.xml" overwrite="true"/>
        <ear destfile="${jar.dir}/BankApplication.ear" appxml="${build.dir}/application.xml">
          <fileset dir="${jar.dir}">
              <include name="BankEJBModule.jar"/>
              <include name="ClientModule.jar"/>
          </fileset>
        </ear>
      </target>
    
      <property name="j2ee.home"   value="${env.J2EE_HOME}" />
      <property name="admin.user"  value="admin" />
      <property name="admin.pass"  value="password" />
      <property name="appname"     value="BankApplication"/>
      <property name="ear.file"    value="${jar.dir}/${appname}.ear" />
    
      <target name="setAsadmin" >
         <condition property="asadmin" value="asadmin.bat">
            <os family="windows"/>
         </condition>
         <condition property="asadmin" value="asadmin">
            <not>
               <os family="windows"/>
            </not>
         </condition>
      </target>
    
      <target name="deploy" depends="assemble-app,setAsadmin">
        <echo message="Deploying ${ear.file}."/>
        <exec dir="." executable="${j2ee.home}/bin/${asadmin}">
            <arg line=" deploy"/>
            <arg line=" --user ${admin.user}"/>
            <arg line=" --password ${admin.pass}"/>
            <arg line=" --force=true"/>
            <arg line=" --name ${appname}"/>
         <arg line=" --retrieve=." />
            <arg line=" ${ear.file}"/>
         </exec>   
      </target>
    
      <target name="get-stubs" depends="setAsadmin">
        <echo message="Retrieving stubs JAR file for ${appname}."/>
        <exec dir="." executable="${j2ee.home}/bin/${asadmin}">
            <arg line=" get-client-stubs"/>
            <arg line=" --user ${admin.user}"/>
            <arg line=" --password ${admin.pass}"/>
            <arg line=" --appname ${appname}"/>
            <arg line=" ."/>
         </exec>   
      </target>
    
      <target name="undeploy" depends="setAsadmin">
        <echo message="Undeploying ${appname}."/>
        <exec dir="." executable="${j2ee.home}/bin/${asadmin}">
            <arg line=" undeploy"/>
            <arg line=" --user ${admin.user}"/>
            <arg line=" --password ${admin.pass}"/>
            <arg line=" ${appname}"/>
         </exec>   
      </target>
    
      <target name="test">
        <junit printsummary="on" haltonfailure="no" filtertrace="off">
          <classpath>
            <pathelement location="${build.dir}"/>
            <pathelement path="${java.class.path}"/>
            <pathelement path="BankApplicationClient.jar" />
          </classpath>
    
         <formatter type="plain" usefile="no"/>
          <test name="bank.BankMgrTest"/>
        </junit>
      </target>
    
    
      <target name="clean">
        <delete dir="${build.dir}" />
        <delete dir="${jar.dir} "/>
      </target>
    
    </project>