首页 > 解决方案 > 如何在 ant 脚本中运行 Maven 命令?

问题描述

我正在尝试创建一个 ant 任务来执行 maven 命令,但是在运行 ant 任务时出现错误

<target name="Junit">
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="E:\EOM Setup\maven-3.3.9\bin\mvn.bat"/>
<arg value="test" />
</exec>
</target>

运行此程序时,出现错误:'E:\EOM' 不被识别为内部或外部命令、可运行程序或批处理文件(我在 Windows 7 上运行)

标签: shellmavenjenkinscommand-lineant

解决方案


您可以通过使用带有属性(而不是更常见的属性)的 Antproperty任务来解决这个问题。这会将值存储为格式正确的路径。此外,您可以使用它来引用 mvn.bat,而不是每次都输入整个路径。locationvalue

<target name="Junit">
    <property name="mvn.executable" location="E:\EOM Setup\maven-3.3.9\bin\mvn.bat" />

    <exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
        <arg value="/C"/>
        <arg value="${mvn.executable}"/>
        <arg value="test" />
    </exec>
</target>

推荐阅读