Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

[junit] java.lang.ClassNotFoundException: UserActivityTest

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Haifeng Jiang
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic