Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / November 2006

Tip: Looking for answers? Try searching our database.

Apache Ant Question

Thread view: 
list.cj@gmail.com - 27 Nov 2006 21:54 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.