tags:

views:

317

answers:

2

Hi All,

When I run javadoc on my java source code, I get this error for th Junit test class:

[javadoc] /mypath/TestStuff.class: warning: Cannot find annotation method 'expected()' in type 'org.junit.Test': class file for org.junit.Test not found

The problem appears with junit version 4 with this type of annotation:

@Test(expected=Exception.class)

Obvisouly, it sounds like javadoc cannot find org.junit.Test but why would it need it in the 1st place ? How do I fix that ?

Cheers David


UPDATE:

the junit jar is not on my project classpath but is in $ANT_HOME/lib. This way, I don't have to add it to my project lib folder and the junit ant target works fine.

It sounds like the javadoc target in ant doesn't use the $ANT_HOME/lib to look for jars

+1  A: 

org.junit.Test is the class defining the @Test annotation that you're using. Sounds like you need to add the junit jar to the classpath.

EDIT: I set up projects with ant to use 2 classpaths, one for regular classes and one for test-only stuff, and I add junit to the test-only classpath.

Nathan Hughes
just updated my question regarding your comment
DavidM
+1  A: 

You need to tell the javadoc task in ant where to find junit, using "classpath", or "classpathref" attributes or a nested <classpath> element.

Something like

 <javadoc ...>
     ...
     <classpath path="path/to/your/junit.jar"/>
     <!-- or maybe "${env.ANT_HOME}/lib/junit.jar" ? -->
 </javadoc>

See http://ant.apache.org/manual/CoreTasks/javadoc.html for reference.

It might mean that you'll have to store junit.jar in the project, since it's easier to reference that way.

Christoffer Hammarström
yes, it might be indeed easier to add it the project... using the environment variable ANT_HOME is not safe at all since it is not set up systematically on all systems.
DavidM