• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

[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!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic