You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by a1slowhand <ro...@yahoo.com> on 2009/05/29 17:35:27 UTC

Newbie question concerning ant javac

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


Re: Newbie question concerning ant javac

Posted by a1slowhand <ro...@yahoo.com>.
Thanks for the tips.  I liked the idea of the java compile options and will
use it.  i got the source and sub-source compiled worked out.  Since there
is not many sub-source applications, I just have a text file in each
sub-directory that is a list of excluded files to compile.   Compile snippet
follows:

  <target name="copy" depends="clean,create_dirs">
    <copy todir="${tmp}">
		<fileset dir="${tmpsrc}" casesensitive="no">
			<include name="/*.java"/>
			<excludesfile name="${basedir}\exclude.txt"/>
		</fileset>
	</copy>
	    <copy todir="${tmp}">
		<fileset dir="${source}" casesensitive="no">
			<include name="/*.java"/>
		</fileset>
	</copy>
  </target>



  <target name="compile" depends="clean,create_dirs,copy" >
    <javac destdir = "${basedir}/classes" compiler ="javac1.3"
executable="C:\jdk1.3\bin\javac" source="1.3" debug="on">
     <src path="${basedir}/tmp"/>  
      <classpath refid="class.path"/> 
    </javac>
    <copy todir="${basedir}/classes">
      <fileset dir="${basedir}">
        <include name="**/*.gif"/>
        <include name="**/*.jpg"/>
        <include name="**/*.png"/>
      </fileset>
      <fileset dir="${basedir}">
        <include name="reports/**/*.*"/>
      </fileset>
    </copy>
  </target>





a1slowhand 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-tp23782206p23815694.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


Re: Newbie question concerning ant javac

Posted by a1slowhand <ro...@yahoo.com>.
Thanks Chuck for the direction.  Fileset was one area that I have looked at,
it seemed like a logicial starting point.   I didnt have much luck with it,
but I will revisit the manual and try some more tests.

Thaks again.
Ron



Chuck Burgess-2 wrote:
> 
> On Fri, May 29, 2009 at 10:35 AM, a1slowhand <ro...@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.
>>
> 
> 
> My first thought here might be to try using a *fileset* to recognize all
> the
> files in the chosen customer directory as the first step.  Once I have
> those
> filenames in hand, I can then use another *fileset* to pick up files in
> the
> top-level dir and exclude filenames that are already found in the customer
> dir fileset.  I don't know if this is a valid interpretation of
> *fileset*usage, but this is the approach that comes to mind to
> research first.
> 
> If using the filesets to attempt compiling directly from the source
> directories doesn't prove feasible, perhaps an intermediate step of
> copying
> only the source files you want (identified by the filesets) to an
> intermediate source directory, and do your compilation against that file
> location.   This approach might mean all the intermediate files look like
> "changed" files due to being copied, but there are ways to tell the COPY
> task to only copy over files that have changed.
> 
> Again, this is all me thinking out loud, and not something I've had to
> attempt myself.
> -- 
> CRB
> 
> 

-- 
View this message in context: http://www.nabble.com/Newbie-question-concerning-ant-javac-tp23782206p23783130.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


Re: Newbie question concerning ant javac

Posted by Chuck Burgess <de...@gmail.com>.
On Fri, May 29, 2009 at 10:35 AM, a1slowhand <ro...@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.
>


My first thought here might be to try using a *fileset* to recognize all the
files in the chosen customer directory as the first step.  Once I have those
filenames in hand, I can then use another *fileset* to pick up files in the
top-level dir and exclude filenames that are already found in the customer
dir fileset.  I don't know if this is a valid interpretation of
*fileset*usage, but this is the approach that comes to mind to
research first.

If using the filesets to attempt compiling directly from the source
directories doesn't prove feasible, perhaps an intermediate step of copying
only the source files you want (identified by the filesets) to an
intermediate source directory, and do your compilation against that file
location.   This approach might mean all the intermediate files look like
"changed" files due to being copied, but there are ways to tell the COPY
task to only copy over files that have changed.

Again, this is all me thinking out loud, and not something I've had to
attempt myself.
-- 
CRB

Re: Newbie question concerning ant javac

Posted by David Weintraub <qa...@gmail.com>.
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 <ro...@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