Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

Ant & JUnit java.lang.NullPointerException

Thread view: 
lionelv@gmail.com - 11 Nov 2007 10:50 GMT
I'm migrating from Netbeans to setup all of my compiling, packaging
and testing. However, I'm having troubles getting the testing part
working. Here's the snippet of code I'm currently using:

   <property name="src"             value="src"/>
   <property name="lib"             value="lib"/>
   <property name="build"           value="build"/>
   <property name="dist"            value="dist"/>
   <property name="dist-lib"        value="${dist}/lib"/>
   <property name="src.lib.runtime" value="${lib}/runtime"/>
   <property name="classes"         value="${build}/classes/"/>
   <property name="jar.executable"  value="${dist}/$
{ant.project.name}.jar"/>
   <property name="test.src"        value="test"/>
   <property name="test.execute"    value="${build}/test"/>
   <property name="test.reports"    value="${test.execute}/reports"/>

   <!-- Runs the JUnit Tests -->
   <target name="test">
       <mkdir dir="${test.reports}"/>
       <copy todir="${test.execute}">
           <fileset dir="${src}"/>
       </copy>
       <copy todir="${test.execute}">
           <fileset dir="${test.src}"/>
       </copy>
       <javac srcdir="${test.execute}"
       classpath="${classpath}"
       debug="true"
       source="1.5"
       />
       <junit dir="${test.execute}">
           <test name="tciworks.analysis.BayesianTest"/>
       </junit>
       <!--junit printsummary="yes">
           <formatter type="plain"/>
           <batchtest fork="yes" todir="${test.reports}">
               <fileset dir="${test.execute}}">
                   <include name="**/*Test*.java"/>
               </fileset>
           </batchtest>
       </junit-->
   </target>

Code being tested is in ${src}
Test cases are in ${test.src}.
All of the source is copied to ${test.execute} and compiled there.

When I try to test I get the following (trimmed) error:

Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: build.xml
Detected Java version: 1.5 in: c:\Program Files\Java\jdk1.5.0_06\jre
Detected OS: Windows XP
[antlib:org.apache.tools.ant] Could not load definitions from resource
org/apache/tools/ant/antlib.xml. It could not be found.
[snip]
test:
   [mkdir] Skipping c:\TCIWorks\TCIWorksApplication\build\test
\reports because it already exists.
    [copy] tciworks\TCIWorks.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\TCIWorks.java is up to date.
    [copy] tciworks\UpdateManager.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\UpdateManager.java is up to
date.
    [copy] tciworks\analysis\AbstractObjective.java omitted as c:
\TCIWorks\TCIWorksApplication\build\test\tciworks\analysis
\AbstractObjective.java is up to date.
[snip]
   [javac] tciworks\util\TCIFigures.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCIFigures.class is up
to date.
   [javac] tciworks\util\TCISwingWorker.class skipped - don't know
how to handle it
   [javac] tciworks\util\TCISwingWorker.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCISwingWorker.class is
up to date.
   [javac] tciworks\util\TCIWorksConstants.class skipped - don't know
how to handle it
   [javac] tciworks\util\TCIWorksConstants.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCIWorksConstants.class
is up to date.

BUILD FAILED
c:\TCIWorks\TCIWorksApplication\build.xml:134:
java.lang.NullPointerException
    at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
115)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:
1329)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
    at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
    at org.apache.tools.ant.Main.runBuild(Main.java:698)
    at org.apache.tools.ant.Main.startAnt(Main.java:199)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.NullPointerException
    at org.apache.tools.ant.types.Path.add(Path.java:261)
    at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:
753)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
288)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
105)
    ... 11 more
--- Nested Exception ---
java.lang.NullPointerException
    at org.apache.tools.ant.types.Path.add(Path.java:261)
    at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:
753)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
288)
Arne Vajhøj - 12 Nov 2007 02:32 GMT
> I'm migrating from Netbeans to setup all of my compiling, packaging
> and testing. However, I'm having troubles getting the testing part
> working. Here's the snippet of code I'm currently using:

>         <junit dir="${test.execute}">
>             <test name="tciworks.analysis.BayesianTest"/>
[quoted text clipped - 19 lines]
> Detected Java version: 1.5 in: c:\Program Files\Java\jdk1.5.0_06\jre
> Detected OS: Windows XP

> Caused by: java.lang.NullPointerException
>     at org.apache.tools.ant.types.Path.add(Path.java:261)

Very hard to say without having the code to play with.

You could try replace:

<junit dir="${test.execute}">

with:

<junit fork="on" dir="${test.execute}">

because I have often had problems without that.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.