【问题标题】:"testng doesn't support the nested "java" element."- while executing build.xml - JAR target“testng 不支持嵌套的“java”元素。”- 在执行 build.xml 时 - JAR 目标
【发布时间】:2018-01-12 10:11:02
【问题描述】:

我们想从远程机器创建 Jar、部署和执行 jar 文件。

根据testNG的规定创建主类文件

当从这个类文件运行时它完美执行,但是当执行表单构建 XML 时出现以下错误

"testng 不支持嵌套的 "java" 元素。"

  1. TestNG 版本 - 6.13.1(也尝试使用较低版本)
  2. Eclipse - Neon.3 发布 (4.6.3)
  3. 硒 - 3.7.1
  4. 蚂蚁 - 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


【解决方案1】:

我认为问题是由于在您的&lt;target name="runs" depends="compile,JarCreation"&gt; 中包含&lt;java jar="${jar.dir}/${ws.project.name}.jar" fork="true"/&gt;

要解决此问题,您需要从 &lt;testng&gt; 元素中删除 &lt;java&gt; 元素并重试。

有关可用选项的更多信息,请参阅here

【讨论】:

  • 谢谢你 Krishnan,根据你的方向去解决。对延迟响应表示歉意。
【解决方案2】:
<!-- Runs the file and generates Reportng report for TestNG-->
<taskdef resource="testngtasks" classpath="${dependencies}/testng-6.9.9.jar" />
<target name="testng-execution" depends="jarextraction">
    <testng testjar="${cashkaroJar}" xmlPathInJar="local/${xmlFile}" classpathref="classpath" useDefaultListeners="true">
        <sysproperty key="env.URL_key" value="CK_AUTO_DEV"></sysproperty> 
    </testng>
</target>

【讨论】:

    猜你喜欢
    • 2015-10-21
    • 2015-10-27
    • 2016-12-16
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2023-01-14
    • 2020-07-31
    相关资源
    最近更新 更多