Domanda

We have an automated build process that uses Nant scripts, and we just inherited a Java project that has an existing, working Ant script. I have searched all over and it seems most people use a batch file to call Ant scripts from Nant. This seems a little hacky to me. Is there a way to call Ant scripts directly from Nant in task format?

This similar question addresses it with a batch file but I want to do it without.

È stato utile?

Soluzione

<!-- calling the Ant build Process-->
    <target name="AntBuildProcess" description="Created to call the Ant build during this NAnt build process" >
        <echo message="Starting the Ant Build Process..." />
        <exec program="ant" commandline='-buildfile YourAntBuild.xml' failonerror="true"/>
    </target>

Then during your Build process, you just call this target at the point you need it to be built. <call target="AntBuildProcess" />

Altri suggerimenti

Ant is a batch file. Take a look, and you'll see a file called ant.bat in the %ANT_HOME%\bin directory.

Ant is actually a Java program, so you could launch it from the java command by running the class org.apache.tools.ant.launch.Launcher which is basically what the ant.bat file is doing.

However, why reinvent the wheel? The ant.bat runs the Java command the right way, gives you options to change the way it's executed, and makes sure everything is setup correctly.


Addendum

I see, Nant, unlike Ant, will always call cmd.exe and use suffixes and %PATHEXEC% to figure out if something is a batch script or other type of script. Thus, if you want to run Ant using Ant as a batch script via <exec/> you would do this:

<exec executable="cmd.exe"
    dir="${working.dir}">
    <arg value="/c"/>
    <arg value="ant.bat"/>
</exec>

However, in Nant you can simply do it this way:

<exec program="ant"
    workingdir=${working.dir}"/>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top