Can I build multiple projects from one build-file. Example:
<project basedir="." default="all" name="app1">
...
</project>
<project basedir="." default="all" name="app2">
...
</project>
Currently I type ant -f build1.xml compile
and it builds my application and I have to use two separate build files. Is there some way to get it running in a way that i have both the projects defined a common build-file and I can type something like ant app1 compile
or ant app2 compile
?
Here's what my build-file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project name="azebooster" default="dist" basedir=".">
<!-- Globals -->
<property name="src" location="src/com/aelitis"/>
<property name="build" location="build/azebooster"/>
<property name="jar" location="jar/azebooster"/>
<property name="resources" location="res/azebooster"/>
<!-- Paths -->
<path id="classpath">
<fileset dir="." includes="**/*.jar"/>
</path>
<!-- Start it -->
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${jar}"/>
</target>
<!-- Build it -->
<target name="compile" depends="init" description="compile the source" >
<javac srcdir="${src}" destdir="${build}">
<classpath>
<path refid="classpath"/>
</classpath>
</javac>
</target>
<!-- Jar it -->
<target name="jar" depends="compile">
<jar destfile="${jar}/${ant.project.name}.jar">
<fileset dir="${build}"/>
<fileset dir="${resources}" />
</jar>
</target>
<!-- Clean it -->
<target name="clean" description="clean up" >
<tstamp/>
<delete dir="${build}"/>
<delete dir="${jar}"/>
</target>
</project>
Thank you.
Ant uses an xml file for its configuration. The default file name is build. xml . Ant builds are based on three blocks: tasks, targets and extension points. A task is a unit of work which should be performed and constitutes of small atomic steps, for example compile source code or create Javadoc.
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.
A target is a container of tasks and datatypes that cooperate to reach a desired state during the build process.
Yes you can create a default.build file (in this way you don't need to specify the file, because it's used by default). On it you can create the following targets:
<target name="all" depends="app1, app2" />
<target name="app1">
<ant antfile=<app1file> target="compile" />
</target>
<target name="app2">
<ant antfile=<app2file> target="compile" />
</target>
On this way you can use both ant file from one unique file.
And you can do all in only one file, if you replace the app1 and app2 targets, with the needed targets to compile them that you have in the separate files.
EDITED:
You have different ways to include both of them in only one file, maybe the easiest one is include a suffix for each project on each target. And you can call the specific project target or the target for both.
I put you an example with the compile target (and for init target too).
You can use compile for compile both projects (I call the other project other), and compileazeboster to compile the azeboster project.
You can search the common things to avoid the innecesary duplicated code (common paths, targets and so on)
<property name="srcazebooster" location="src/com/aelitis"/>
<property name="buildazebooster" location="build/azebooster"/>
<property name="jarazebooster" location="jar/azebooster"/>
<property name="srcother" location="src/other"/>
<property name="buildother" location="build/other"/>
<property name="jarother" location="jar/other"/>
<!-- Start it -->
<target name="init" depends="initazebooster, initother"/>
<!-- Build it -->
<target name="compile" depends="compileazebooster, compileother" description="compile the source for all" />
<!-- Start azebooster-->
<target name="initazebooster">
<tstamp/>
<mkdir dir="${buildazebooster}"/>
<mkdir dir="${jarazebooster}"/>
</target>
<!-- Build azeboster-->
<target name="compileazebooster" depends="initazebooster" description="compile the source for azebooster" >
<javac srcdir="${srcazebooster}" destdir="${buildazebooster}">
<classpath>
<path refid="classpath"/>
</classpath>
</javac>
</target>
<!-- Start other-->
<target name="initother">
<tstamp/>
<mkdir dir="${buildotherr}"/>
<mkdir dir="${jarother}"/>
</target>
<!-- Build other-->
<target name="compileother" depends="initother" description="compile the source for other" >
<javac srcdir="${srcother}" destdir="${buildother}">
<classpath>
<path refid="classpath"/>
</classpath>
</javac>
</target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With