我创建了一个基本的selenium项目,我试图使用ant运行testNG。 我在运行ant run时遇到此错误。 upto编译,构建是可以的。
我从Internet上找到的一些解决方案是在我的类路径中添加Jcommander.jar,但它已经添加到我的类路径中。这是我在CMD中得到的错误
run:
[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.privateGetMethodRecursive(Unknown Source)
[testng] at java.lang.Class.getMethod0(Unknown Source)
testng] at java.lang.Class.getMethod(Unknown Source)
[testng] at sun.launcher.LauncherHelper.validateMainClass(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.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] ... 7 more
[testng] Error: A JNI error has occurred, please check your installation and try again
testng] The tests failed.
这是我的类路径
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/selenium-java-2.53.0.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/selenium-java-2.53.0-srcs.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/apache-mime4j-0.6.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/bsh-2.0b4.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/commons-codec-1.10.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/commons-exec-1.3.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/commons-io-2.4.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/gson-2.3.1.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/guava-19.0.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/httpclient-4.5.1.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/httpcore-4.4.3.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/httpmime-4.5.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/jcommander-1.48.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/jna-4.1.0.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/jna-platform-4.1.0.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/junit-4.12.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/netty-3.5.7.Final.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/phantomjsdriver-1.2.1.jar"/>
<classpathentry kind="lib" path="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs/testng-6.9.9.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
答案 0 :(得分:0)
您已列出Eclipse用于管理其类路径的文件,但ANT不使用此文件。
ANT是一个单独的工具,有一个&#34; build.xml&#34;详细说明了它的构建逻辑。要管理您的ANT类路径,我建议使用以下构造:
<property name="lib.dir" location="C:/Users/ASOKE/Desktop/Selenium All Docs/Jar files/selenium-2.53.0/libs"/>
<path id="compile.path">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
可以用来编译jar文件如下:
<target name="compile" description="Compile code">
<mkdir dir="${build.dir}/classes"/>
<javac srcdir="${src.dir}" destdir="${build.dir}/classes" includeantruntime="false" debug="true" classpathref="compile.path"/>
</target>
希望这能让您了解ANT的工作原理。
总之,不要忘记Eclipse是一个开发人员工具,并且拥有自己构建Java的机制。人们使用ANT,Maven和Gradle等备用构建工具的原因是因为生成构建通常发生在没有GUI工具的专用构建服务器上。
<强> PS 强>