ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yoshimitsu, Stacy D." <SYOSHIMI...@northropgrumman.com>
Subject RE: File dependency
Date Wed, 12 Feb 2003 22:55:41 GMT
Hi Mike,

You know, I'd ran into the same problem and here's what I did.  I'm not sure
if that's the correct way thought (I'm new to Ant too :P), but it works.

Here is what my build.xml file will do:
1)  I need to built mission.jar which depends on some jar files in the libs
directory
2)  I need to built textEditor.jar which depends on mission.jar



Here is my directory structures:  I copy all my dependency jar files to the
libs directory.
----------------------------------
home.dir				./
src.dir				./src
build.dir				./build
libs.dir				./libs
dist.dir				./dist
mission.classes.dir		./build/Mission_classes
textEditor.classes.dir		./build/TextEditor_classes
...


_______build.properties______________
home.dir	 	= "."
src.dir		= src
build.dir	 	= build
libs.dir	 	= Libs
dist.dir	 	= Dist
mission.classes.dir	= ${build.dir}/Mission_classes
textEditor.classes.dir  = ${build.dir}/TextEditor_Classes
...



_______build.xml__________________

<target name="init">
    <tstamp/>

    <!-- Initializing the necessary variables to do the build. -->
    <property file="build.properties" />

    <!-- this is where I set up the path to point to my dependency jar files
-->
    <path id="3rdParty_jars">
	<fileset dir="${libs.dir}">
	    <include name="*.jar" />
	</fileset>
    </path>

</target>

....

<!--   (1)  Build mission.jar -->
<target name="build_mission" depends="prepare">

    <javac srcdir="${src.dir}" 
	   destdir="${mission.classes.dir}"
	   includes="${javac.mission.includes}"
	   excludes="${javac.mission.excludes}"  >

      <!-- this is where I point to to get my dependency jar files -->
	<classpath refid="3rdParty_jars" />
    </javac>

    <jar destfile="${dist.dir}/${mission.name}.jar"  
 	 basedir="${mission.classes.dir}"/>
</target>


<!--  (2) built textEditor.jar  
	I need to make sure Mission.jar exist before building textEditor.jar
-->

<!-- this sets Mission.jar.exist to true if it exist in the ./dist
directory.  -->
<target name="Mission.jar.exist" depends="init">
    <available property="Mission.jar.exist"
	file="${dist.dir}/${mission.name}.jar" />
</target>


<!-- If Mission.jar.exist is true, then execute the following target.  -->
<target name="build_textEditor" depends="Mission.jar.exist"
if="Mission.jar.exist">
   
    <!-- copy if mission.jar exist in ./dist, copy it to ./libs directory.
-->
    <copy file="${dist.dir}/${mission.name}.jar"  todir="${libs.dir}" />

    <javac srcdir="${src.dir}" 
	   destdir="${textEditor.classes.dir}"
	   includes="${javac.textEditor.includes}"  >
	<classpath refid="3rdParty_jars" />
    </javac>

    <jar destfile="${dist.dir}/${textEditor.name}.jar"  
 	 basedir="${textEditor.classes.dir}"/>

</target>
________________________

If anyone thinks this is not a good method, please let me know.  Otherwise
I'll be in trouble.  :P

Stacy




-----Original Message-----
From: Mike Ayers [mailto:mayers@NEVIKNETWORKS.com]
Sent: Wednesday, February 12, 2003 1:48 PM
To: user@ant.apache.org
Subject: File dependency



	Hello,

	I feel rather embarassed to be asking what I would expect to be a
trivial question, but I can't seem to figure out how to create a file
dependency.  There is an external jar file that needs to be built (it is the
product of another archive module) before my module can be built, and I want
to check if it exists before compiling, because things go quite badly if
it's not there, and the error messages thus generated aren't terribly
helpful.  I tried:

=======SNIP==========8<-----------------------------------------

  <target name="test.compile"
          depends="init,${maindist}/hub.jar" >
    <javac srcdir="${src}" destdir="${classes}" deprecation="off" >
       <classpath refid="test.classpath" />
    </javac>
  </target>

=======SNIP==========8<-----------------------------------------

	...where init is an ant target (that works fine), maindist is a
property with the path to the jar, and hub.jar is its name.  I get:


=======SNIP==========8<-----------------------------------------

C:\test>ant
Buildfile: build.xml

BUILD FAILED
Target `${maindist}/hub.jar' does not exist in this project. It is used from
target `test.compile'.

Total time: 0 seconds

=======SNIP==========8<-----------------------------------------

	...which is consistent with the ant documentation, which states that
dependencies are ant targets.  So, I think the question here is: how do I
get a file to be an ant target?

	Am I missing something here?


	TiA,

/|/|ike

Mime
View raw message