ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <qazw...@gmail.com>
Subject Re: Newbie question concerning ant javac
Date Sun, 31 May 2009 05:46:31 GMT
You can use <src> to select the source directories you want to compile:

<property name="target.dir" value="${basedir}/target"/>
<property name="customer.dir" value="CustomerYY"/>
<property name="javac.source" value="1.3"/>
<property name="javac.target" value="1.3"/>
<target name="compile">
   <mkdir dir="${target.dir}/compile"/>
   <javac
       destdir="${target.dir}/compile"
       source="${javac.source}"
       target="${javac.target}">
        <src dir="${source.dir}/TopSrc">
            *<include file="*.java"/>*
       </src>
       <src dir="${source.dir}/${customer.dir}"/>
   </javac>

By saying <include file="*.java"/>, I eliminate all sub-directories from my
compile path including the customer directories. However, it also may
eliminate any other subdirectories I might also want that aren't customer
directories. You might be able to do this too:

   <javac
       destdir="${target.dir}/compile"
       source="${javac.source}"
       target="${javac.target}">
        <src dir="${source.dir}/TopSrc">
            *<exclude Customer*/**"/>*
       </src>
       <src dir="${source.dir}/${customer.dir}"/>
   </javac>

That *should* include all subdirectories, but the ones that start with
Customer*. However, I've never tried it, so I am not 100% sure it will work.

One hint: You can use <property> to set defaults that can be overridden on
the command line. I normally include a bunch of <javac> defaults:

<property name="javac.destdir" value="{target.dir}/classes"/>
<property name="javac.src" value="${basedir}/src"/>
<property name="javac.nowarn" value="off"/>
<property name="javac.debug" value="off"/>
<property name="javac.debuglevel" value="lines,vars,source"/>
<property name="javac.deprecation" value="off"/>
<property name="javac.listfiles" value="false"/>
<property name="javac.verbose" value="false"/>
<property name="javac.failonerror" value="true"/>

<target name="compile">
    <javac
        destdir="${javac.destdir}"
        srcdir="${javac.srcdir}"
        nowarn="${javac.nowarn}"
        debug="${javac.debug}"
        debuglevel=${javac.debuglevel}"
        deprecation=${javac.deprecation}"
        listfiles="${javac.listfiles}"
        verbose="${javac.verbose}"
        failonerror="${javac.failonerror}"/>


Now, let's say a developer decides he needs to list the files that are
getting compiled, and he wants verbose output from the javac task, he could
invoke Ant this way:

    $ ant -Djavac.listfiles="true" -Djavac.verbose="true" compile

This will override the default settings in the <javac> task without having
to modify the actual build.xml file itself.

And, one more hint: We always create a subdirectory called "target" under
the ${basedir} where we put all our compiled and workfiles. This makes
cleaning up very easy since all I have to do is delete the target directory.
It makes it much easier to write our clean target. Plus, if you use a source
control system, your build generated files aren't intermingled with the
actual source code and prevents developers from accidently checking in build
generated files.

On Fri, May 29, 2009 at 11:35 AM, a1slowhand <ron_dump@yahoo.com> wrote:
>
> My company is just now moving to Ant and I have been given the task of
moving
> it.  I have been able to compile our main source directory, so I know I
have
> Ant installed and working propertly. We have our based code, and then
custom
> code underneath that narrows the based code. My problem is how to select
> "certain" source files for the compile.
>
> |TopSrc source dir  <-- based code
> |    main.java
> |    a.java
> |    b.java
> |--|CustomerXX <-- narrowed code
> |--    b.java
> |--|CustomerYY <-- another customer code narrowed
> |--    a.java
> |--    b.java
>
> What I would like to do is after making the changes to CustomerXX\b.java
> compile grabbing TopSrc\main.java  & TopSrc\a.java &
> TopSrc\CustomerXX\b.java, and ensuring that TopSrc\b.java is NOT selected
to
> advoid a duplicate class error from the compile.  Similar process would
> happen when changing CustomerYY's code.  I only need to compile the
Customer
> that changed.  The closest that I have come is to compile source directory
> and all sub-directories.  Which Javac complains of duplicate classes when
it
> compiles one of the sub-directories java apps with the same name as one in
> the root source directory.
>
> <project name="AAAtest" default="make_jar" basedir=".">
>        <property name="source" location="C:\Documents and
Settings\Ron\TopSrc"/>
>        <property name="build" location="C:\Documents and
Settings\Ron\TopSrc"/>
>        <property name="dist"  location="dist"/>
> <!--  Which customer -->
>        <input
>                message="Please enter the Customer to build:"
>                addproperty="build.cust"
>                defaultvalue="AAAtest"
>        />
>
>        <path id="class.path">
>                <fileset dir="lib">
>                <include name="**/*.jar"/>
>                </fileset>
>        </path>
>
>
>  <target name="init">
>     <property name="project_name"   value="auction"/>
>     <property name="jar"
> value="${basedir}/${build.cust}/${project_name}.jar"/>
>     <property name="mainclass"      value="myTest"/>
>     <property name="DataDir"  value="${basedir}/${build.cust}/data"/>
>    <tstamp/>
>  </target>
>
>  <target name="create_dirs" depends="init">
>    <mkdir dir="${basedir}/${build.cust}/classes"/>
>    <mkdir dir="${basedir}/${build.cust}/lib"/>
>    <mkdir dir="${basedir}/${build.cust}/jar"/>
>  </target>
>
>  <!-- CLEAN TARGET -->
>
>  <target name="clean">
>    <delete dir="${basedir}/${build.cust}/classes"/>
>  </target>
>
>  <!--COMPILE TARGET  -->
>  <target name="compile" depends="clean,create_dirs">
>    <javac destdir = "${basedir}/${build.cust}/classes" source="1.3"
> debug="on">
>      <src path="${basedir}"/>
>      <exclude name="**/_*.java"/>
>      <classpath refid="class.path"/>
>    </javac>
>    <copy todir="${basedir}/${build.cust}/classes">
>      <fileset dir="${basedir}/${build.cust}">
>        <include name="**/*.gif"/>
>        <include name="**/*.jpg"/>
>        <include name="**/*.png"/>
>      </fileset>
>      <fileset dir="${basedir}/${build.cust}">
>        <include name="reports/**/*.*"/>
>      </fileset>
>    </copy>
>  </target>
>
>
>  <!-- MAKE JAR TARGET -->
>  <target name="make_jar" depends="compile">
>    <jar basedir="${basedir}/${build.cust}/classes"
>         jarfile="${basedir}/${project_name}.jar"
>         manifest="${basedir}/manifest.add"
>         includes="**/*.*"/>
>    <copy todir="${basedir}/${build.cust}/jar">
>      <fileset dir="${basedir}/${build.cust}/lib">
>        <include name="**/*.jar"/>
>      </fileset>
>    </copy>
>  </target>
>
> </project>
>
>
> Any help at this point would be great!  Even if it's to point me to the
> right place in the manual.  I have no problem reading and studing, but the
> terminology Ant uses is not what I know.  That makes it hard to lookup the
> task I'm trying to accomplish.
>
> Thanks to all.
> Ron
>
>
>
>
> --
> View this message in context:
http://www.nabble.com/Newbie-question-concerning-ant-javac-tp23782206p23782206.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
David Weintraub
qazwart@gmail.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message