wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes [junit] java.lang.ClassNotFoundException: UserActivityTest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "[junit] java.lang.ClassNotFoundException: UserActivityTest" Watch "[junit] java.lang.ClassNotFoundException: UserActivityTest" New topic
Author

[junit] java.lang.ClassNotFoundException: UserActivityTest

Haifeng Jiang
Ranch Hand

Joined: Dec 14, 2008
Posts: 42
Hello everyone!
When I 'ant test' in command line to run my Junit test class, I continue getting ClassNotFoundException.

My build.xml is as below:


The output when 'ant test' in command line:


I am sure that the UserActivityTest.class is under ${class.dir} directory. Could anyone help on this? Thanks so much!

Thinking a lot. Gaining a lot.
Haifeng Jiang
Ranch Hand

Joined: Dec 14, 2008
Posts: 42
I modified the build.xml file:


But when run 'ant test', I still got error:


This time the error should be caused by my test class. But I don't know what's wrong in my test class, could you please have a look?

BTW, when I use Eclipse to 'Run As -> JUnit Test', it works fine.
Haifeng Jiang
Ranch Hand

Joined: Dec 14, 2008
Posts: 42
Now I go further...
but still got problem with the 'file path'

see here:
File file = new File("../config/log4j.properties"); //in this way, ant works, but use eclipse run ant doesn't work
File file = new File("./config/log4j.properties"); //in this way, ant doesn't work, but eclipse works
Anyone who know the solution, please help!!!
Haifeng Jiang
Ranch Hand

Joined: Dec 14, 2008
Posts: 42
seems I am helping myself to fix the problem.

The error is caused by the path of build.xml. When I put it under <project_dir>/ant/ , Ant didn't work. So I put it under <project_dir>, then Ant works for me.
It caused by the relative path.
<project name="XXX" basedir="." default="run"> -- in build.xml
public static final String LOG4J_CONFIG_FILE_PATH = "./config/log4j.properties"; --in my Java class

build.xml should always put under project directory directly. In this way, it will avoid some unnecessary troubles.
Also http://ant.apache.org/manual/Tasks/java.html, it help me a lot!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [junit] java.lang.ClassNotFoundException: UserActivityTest
 
Similar Threads
Help with properties file
ant exception
Ant build fail, sometimes 'cause ant forgets property
Ant+JUnit
Assignment submission file structure verification / ant build.xml