1
votes

This Ant-Target works:

<target name="run">
    <java jar="dist/FBChatSoft.jar" fork="true"/>
</target>

so "dist/FBChatSoft.jar" is the correct path to the jar.

But the following target doesn't work. The Path to the *Test.java is also correct.,

<target name="junit" depends="jar">
    <mkdir dir="junitreport"/>
    <junit printsummary="yes">
        <classpath>
            <path location="dist/FBChatSoft.jar"/>
        </classpath>

        <formatter type="xml"/>

        <batchtest fork="yes" todir="junitreport">
            <fileset dir="src/fbchatsoft/client/" includes="*Test.java"/>
        </batchtest>
    </junit>
</target>

<target name="junitreport">
    <junitreport todir="junitreport">
        <fileset dir="junitreport" includes="TEST-*.xml"/>
        <report todir="junitreport"/>
    </junitreport>
</target>

In the JUnitReport I can read:

PropertiesHelperTest

java.lang.ClassNotFoundException: PropertiesHelperTest at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186)

You can find the whole code at: https://bitbucket.org/michaelkohler/fbchatsoft/src

2

2 Answers

0
votes

You need to use **/*Test.java in order to include files recursively.

See the fileset and directory-based tasks documentation.

0
votes

I edited my build.xml and now it looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
<project name="FBChatSoft" default="default" basedir=".">
    <description>Builds, tests, and runs the project FBChatSoft.</description>

    <import file="nbproject/build-impl.xml"/>

    <import file="nbproject/profiler-build-impl.xml"/>

    <target name="clean">
        <delete dir="dist"/>
    </target>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>
    </target>

    <target name="jar">
        <mkdir dir="dist"/>
        <jar destfile="dist/FBChatSoft.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="fbchatsoft.client.FBChatSoft"/>
        <attribute name="Class-Path" value="lib/smack.jar lib/junit-4.5.jar"/>
            </manifest>
        </jar>
    </target>

    <target name="run">
        <java jar="dist/FBChatSoft.jar" fork="true"/>
    </target>

    <target name="junit" depends="jar">
        <mkdir dir="junitreport"/>
        <junit printsummary="yes">
            <classpath>
                <pathelement location="build/classes/"/>
            </classpath>

            <formatter type="xml"/>

            <batchtest todir="junitreport">
                <fileset dir="src/" includes="**/*Test.java"/>
            </batchtest>
        </junit>
    </target>

    <target name="junitreport">
        <junitreport todir="junitreport">
            <fileset dir="junitreport" includes="TEST-*.xml"/>
            <report todir="junitreport"/>
        </junitreport>
    </target>
</project>

Then I added the newest junit package to /usr/share/ant/lib and now it works!