Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different targets on Different OS with Ant

Tags:

ant

I have an ant target I don't want called unless I am running ant on Linux (Not called on Windows)

<target name="jar.all" depends="clean,compile.nic,jar,jar.resources"/>

The target that I don't want called on Windows is: compile.nic

How can I do this?

like image 890
mainstringargs Avatar asked Dec 23 '10 16:12

mainstringargs


People also ask

How do I list all ant targets?

To show every target associated with a build. xml file, you need to run ant -p -v Also, ant -p build.

How do I call ant target from command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What are ant targets?

An Ant target is a sequence of tasks to be executed to perform a part (or whole) of the build process. Ant targets are defined by the user of Ant. Thus, what tasks an Ant target contains depends on what the user of Ant is trying to do in the build script.

What is the difference between task and target?

Online documentation and books say that target is a stage of the entire build process, while task is the smallest unti of work.


2 Answers

Here is a real-world example for Windows vs. UNIX commands. The ELSE improves on previous answers.

<condition property="maven.executable" value="mvn.bat" else="mvn">
  <os family="windows" />
</condition>

<target name="clean">
  <exec executable="${maven.executable}">
    <arg value="clean" />
  </exec>
</target>
like image 186
Steve Jones Avatar answered Oct 18 '22 14:10

Steve Jones


Can I make the Ant copy task OS-specific?

Additionally some tasks support os attribute. for example exec:

<exec executable="cmd" os="windows"/>
like image 40
AlexR Avatar answered Oct 18 '22 14:10

AlexR