如何在没有错误的情况下执行git ant任务

如何在没有错误的情况下执行git ant任务,git,ant,Git,Ant,我已经在ant任务(build.xml)中为git clone创建了小型宏定义,如下所示: <project name="MyProject" default="fileCopy"> <target name="fileCopy" depends="file-checks, local-file, git-file"/> <target name="file-checks"> <available file="rdbms

我已经在ant任务(build.xml)中为git clone创建了小型宏定义,如下所示:

<project name="MyProject" default="fileCopy">

    <target name="fileCopy" depends="file-checks, local-file, git-file"/>

    <target name="file-checks">
       <available file="rdbms1.properties"  property="file.found"/>
    </target>

    <target name="local-file" if="file.found">
        <echo message="File is available in Local" />
    </target>
    <target name="git-file" unless="file.found">
        <git command="clone" options="https://git-wip-us.apache.org/repos/asf/ant.git"/>
    </target>
    <macrodef name="git">
        <attribute name="command" />
        <attribute name="options" default="" />
        <attribute name="dir" default="" />
        <attribute name="failerror" default="false" />
        <element name="args" optional="true" />
        <sequential>
            <echo message="git dir @{dir}" />
            <echo message="git @{command}" />
            <exec executable="git" dir="@{dir}" failonerror="@{failerror}">
                <arg line="@{command} @{options}" />
                <args />
            </exec>
        </sequential>
    </macrodef>
</project>
C:\Users\Haritha\Desktop\H2H\conf\build.xml:14: The following error occurred while executing this line:
C:\Users\Haritha\Desktop\H2H\conf\build.xml:25: Execute failed: java.io.IOException: Cannot run program "git": CreateProcess error=2, The system cannot find the file specified

如何解决此问题以成功执行我的git ant任务而不出现任何错误???

将git.exe的bin路径(类似于C:\Users\Haritha\Desktop\git\bin)添加到路径变量,如下所示。要使其永久更改,如果您使用Windows,可以将其添加为环境变量。

根据您的偏好,您有两个选项

  • 将Git.exe路径添加到build.properties文件
  • 将可执行文件硬编码到ANT脚本中
  • 选项1:将属性值添加到build.properties文件,并将build.xml文件中的可执行文件“git”替换为“${gitEXE}”

    注意:我们使用的是c:/Program Files/git/cmd/git.exe的cmd目录中的git.exe

    <macrodef name="git">
        <attribute name="command" />
        <attribute name="options" default="" />
        <attribute name="dir" default="" />
        <attribute name="failerror" default="false" />
        <element name="args" optional="true" />
        <sequential>
            <echo message="git dir @{dir}" />
            <echo message="git @{command}" />
            <exec executable="${gitEXE}" dir="@{dir}" failonerror="@{failerror}">
                <arg line="@{command} @{options}" />
                <args />
            </exec>
        </sequential>
    </macrodef>
    
    build.properties

    gitEXE=c:/Program Files/Git/cmd/Git.exe

    <macrodef name="git">
        <attribute name="command" />
        <attribute name="options" default="" />
        <attribute name="dir" default="" />
        <attribute name="failerror" default="false" />
        <element name="args" optional="true" />
        <sequential>
            <echo message="git dir @{dir}" />
            <echo message="git @{command}" />
            <exec executable="${gitEXE}" dir="@{dir}" failonerror="@{failerror}">
                <arg line="@{command} @{options}" />
                <args />
            </exec>
        </sequential>
    </macrodef>
    
    
    
    选项2:硬代码可执行文件。首选方案1

    <macrodef name="git">
        <attribute name="command" />
        <attribute name="options" default="" />
        <attribute name="dir" default="" />
        <attribute name="failerror" default="false" />
        <element name="args" optional="true" />
        <sequential>
            <echo message="git dir @{dir}" />
            <echo message="git @{command}" />
            <exec executable="c:/Program Files/Git/cmd/git.exe" dir="@{dir}" failonerror="@{failerror}">
                <arg line="@{command} @{options}" />
                <args />
            </exec>
        </sequential>
    </macrodef>  
    
    
    
    git在您的路径上吗?@almas shaikh..是的,现在我已经在环境变量中设置了git路径。。它正在工作。。非常感谢。