【发布时间】:2018-01-12 10:11:02
【问题描述】:
我们想从远程机器创建 Jar、部署和执行 jar 文件。
根据testNG的规定创建主类文件
当从这个类文件运行时它完美执行,但是当执行表单构建 XML 时出现以下错误
"testng 不支持嵌套的 "java" 元素。"
- TestNG 版本 - 6.13.1(也尝试使用较低版本)
- Eclipse - Neon.3 发布 (4.6.3)
- 硒 - 3.7.1
- 蚂蚁 - 1.10.1
经过长时间的搜索和不同的可能性,我无法得到解决方案。
public static void main(String[] args) {
// Create object of TestNG Class
TestNG runner = new TestNG();
// Create a list of String
List<String> suitefiles = new ArrayList<String>();
// Add xml file which you have to execute
suitefiles.add("D:\\Projects\\TestAutomation\\AgainFinal_Jartest\\TestNG.xml");
// now set xml file for execution
runner.setTestSuites(suitefiles);
// finally execute the runner using run method
runner.run();
}
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac debug="true" destdir="${test.dest}" srcdir="${test.src}" target="1.8" classpath="${test.classpath}" includeantruntime="false">
</javac>
</target>
<target name="JarCreation" depends="compile" description="package, output to JAR">
<!-- Create the distribution directory -->
<mkdir dir="${jar.dir}" />
<echo message="Creating Jarfile ..!"/>
<!-- Put everything in ${build} into the {$ws.project.name}.jar file -->
<jar jarfile="${jar.dir}/${ws.project.name}.jar" basedir="${basedir}" >
<manifest>
<!-- create an executable Jar -->
<attribute name="Main-Class" value="MyWorld.MainTestNGClass"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="build"/>
</jar>
<echo message="Created an executable Jarfile ..!"/>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="run" depends="compile">
<java classname="MyWorld.MainTestNGClass" fork="true"></java>
<sysproperty key="env.key" value="CK_AUTO_DEV"></sysproperty>
</target>
<target name="runs" depends="compile,JarCreation">
<testng classpath="./libs/testng-6.13.1.jar" suitename="Framework for Desktop website">
<java jar="${jar.dir}/${ws.project.name}.jar" fork="true"/>
<sysproperty key="env.key" value="CK_AUTO_DEV"></sysproperty>
</testng>
</target>
【问题讨论】:
-
你能通过主类创建jar文件吗??
-
是的,Siddhesh - 能够创造
-
那么你有什么特别的事情要尝试使用这个构建 xml 来实现吗?
-
只期待一般的事情,比如执行多个目标并创建 Jar,从远程机器部署和执行 jar 文件。
标签: eclipse selenium testng executable-jar build.xml