Ant运行Testng时, java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException错误解决方案

http://www.yiibai.com/html/testng/2013/0916310.html,针对这篇文章介绍的Ant运行Testng,在run as ant build时,提示以下错误:

test:

   [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
   [testng] at java.lang.Class.getDeclaredMethods0(Native Method)
   [testng] at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
   [testng] at java.lang.Class.getMethod0(Unknown Source)
   [testng] at java.lang.Class.getMethod(Unknown Source)
   [testng] at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
   [testng] at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
   [testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
   [testng] at java.net.URLClassLoader$1.run(Unknown Source)
   [testng] at java.net.URLClassLoader$1.run(Unknown Source)
   [testng] at java.security.AccessController.doPrivileged(Native Method)
   [testng] at java.net.URLClassLoader.findClass(Unknown Source)
   [testng] at java.lang.ClassLoader.loadClass(Unknown Source)
   [testng] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   [testng] at java.lang.ClassLoader.loadClass(Unknown Source)
   [testng] ... 6 more
   [testng] The tests failed.
BUILD SUCCESSFUL

Total time: 1 second

原因:

 
 
      

   

在执行这个target时,classpathref=“classpath.test”引用的lib文件夹中没有找到jcommander.jar包,因此找不到com/beust/jcommander/ParameterException

解决办法:网上找到jcommander.jar包,下载后放到工程目录中的lib目录下,重新运行即可

你可能感兴趣的:(Ant)