I'm fairly new to Ant, but I've been through the docs and I can't seem
to address the problem I'm having. Perhaps someone can help me.
I'm trying to create a path based on a conditional. Basically, I want
to include certain things in my classpath if I'm on windows vs linux.
This is the standard classpath regardless of platform:
<path id="project.class.path">
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
This is my lovely conditional that I assume is setting the correct
property. My tests indicate that this works.
<target name="osname" description="os test">
<condition property="isLinux">
<os name = "Linux"/>
</condition>
<condition property="isWindows">
<os name = "Windows"/>
</condition>
</target>
These next two targets are where I would love to put in the dirty work
to fill out the classpath.
<target name="ostest1" depends="osname" if="isLinux">
<echo message="linux"/>
<!-- Insert code here to add linux specific files to classpath -->
</target>
<target name="ostest2" depends="osname" if="isWindows">
<echo message="windows"/>
<!-- Insert code here to add windows specific files to classpath
-->
</target>
This target, while empty, should give me a completed, correct for my
platform, classpath.
<target name="ostestall" depends="ostest1, ostest2">
</target>
I've tried just inserting the snippet below into the ostest* targets
with linux/windows in the appropriate slots, but it doesn't work as I
expected. Basically, if I'm on linux, it always does the windows cp
even though the echo for ostest2 never comes out. Can someone please
explain this and maybe point me in the direction of a fix?
<path id="project.class.path">
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
<include name="linux/*.jar"/>
</fileset>
</path>
Daniel Dyer - 28 Nov 2006 10:36 GMT
> This is my lovely conditional that I assume is setting the correct
> property. My tests indicate that this works.
[quoted text clipped - 39 lines]
> </fileset>
> </path>
I can't see anything obviously wrong in what you have done. However, you
could make this a lot easier. Assuming you have your libraries in
directories that match the possible values for the built-in os.name system
property (i.e. "Windows" and "Linux"), you can do this, without any need
for supporting targets to configure things:
<path id="project.class.path">
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
<include name="${os.name}/*.jar"/>
</fileset>
</path>
Dan.

Signature
Daniel Dyer
http://www.dandyer.co.uk