我创建了一个基本的硒项目,我试图使用ANT使用TestNG运行该项目。在运行蚂蚁运行时,我会遇到以下错误。在编译上,构建还可以。
我从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.
这是我的classpath
<?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>
您已经列出了Eclipse用于管理其classPath的文件,但是ANT不使用此文件。
ant是一个独立的工具,具有" build.xml",可详细介绍其构建逻辑。要管理您的Ant Class Path,我建议以下结构:
<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>
可用于编译罐子如下:
<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>
希望这给您带来蚂蚁的工作方式。
总而言之,不要忘记Eclipse是开发人员工具,并且具有建造Java的机制。人们使用Ant,Maven和Gradle等替代构建工具的原因是因为在没有GUI工具的情况下,通常在专用构建服务器上进行生产。
ps
- 如果您希望Ant和Eclipse共享他们的罐子,那么我建议使用具有Eclipse插件的依赖关系管理工具。