当我通过传递参数通过 eclipse 运行 java 测试文件(单个文件)时
-DappRoot=ECM -DappName=ESW -Dapp.module=FNT -Dapp.env=LOC -DcloneNumber=1
测试文件执行时不会出现错误,如果我不给出参数,则会发生错误,因为无法解析占位符“appRoot”。
我有 junit 目标来生成 html 格式的报告。
<target name="junit" depends="init-junit">
<junit printsummary="on" fork="yes" forkmode="perBatch" haltonfailure="false" failureproperty="junit.failure" showoutput="false">
<classpath>
<path refid="CLASSPATH_JUNIT"/>
</classpath>
<batchtest fork="no" todir="${TEST_BUILD_DIR}">
<fileset dir="${COMP_TEST_SRC}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
<formatter type="xml" />
</junit>
<junitreport todir="${JUNIT_REPORT}">
<fileset dir="${TEST_BUILD_DIR}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${JUNIT_REPORT}"/>
</junitreport>
</target>
当我运行上面的构建脚本时,出现以下错误:无法解析已作为参数传递的占位符“appRoot”。
我通过eclipse将参数传递给build.xml,该参数传递给build.xml文件,但没有传递给java文件。我该如何解决这个问题?
编辑: 尝试使用以下参数:
<junit printsummary="on" fork="yes" forkmode="perBatch" haltonfailure="false" failureproperty="junit.failure" showoutput="false">
<jvmarg value="-DappRoot=ECM" />
<jvmarg value="-DappName=ESW" />
<jvmarg value="-Dapp.module=FNT" />
<jvmarg value="-Dapp.env=LOC" />
<jvmarg value="-DcloneNumber=1" />
<!--<sysproperty key="appRoot" value="${appRoot}"/>
<sysproperty key="appName" value="${appName}"/>
<sysproperty key="app.module" value="${app.module}"/>
<sysproperty key="app.env" value="${app.env}"/>
<sysproperty key="cloneNumber" value="${cloneNumber}"/>-->
<classpath>
<path refid="CLASSPATH_JUNIT"/>
</classpath>
使用系统参数,它工作正常,但需要很长时间才能执行。使用 jvmarg 它不起作用。与
相同的错误 <jvmarg value="-DappRoot=${appRoot}" />
http://ant.apache.org/manual/Tasks/junit.html没有为 sys 和 jvm 参数定义任何限制。
最佳答案
documentation of the junit ant task显示它:
<junit fork="yes" ...>
<jvmarg value="-DappRoot=ECM" />
</junit>
如果 appRoot 属性作为系统属性传递给 ant,您可以将其作为 ant 属性进行访问:
<junit fork="yes" ...>
<jvmarg value="-DappRoot=${appRoot}" />
</junit>
关于java - 将参数从 build.xml 传递到 java 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6545007/