Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath setup by taking jars from multiple directory

 
siba swain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have list of directories mentioned in Build.properties

build.classpath=dir/lib,dir1/lib,dir3/lib,dir5/xyz/lib

I would like to include all the jars present in dir,dir1,dir2,dir3,dir4,dir5. I dont want to define path id for each folder.Is there any way using dirset or fileset i can achieve this or is there any better way


Thanks
 
Santhosh ayiappan
Ranch Hand
Posts: 80
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use the fileset present in the ant script to add all the jars present in a dir.

<javac>
<classpath>
<fileset dir="${lib.dir}">
<include name="*.jar" />
<exclude name="abc.jar" />
</fileset>
</classpath>
</javac>
 
siba swain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Santhosh for quick response.but thing is that all these jars are not under one folder

  • dir/lib
    dir1/lib
    dir2/lib
    dir3/xyz/lib
    dir4/abc/lib.....like this 20 directories


  • if it is inside one parent folder then I would have done using your way. So I thought i would put this in the property file and loop through each folder to create the classpath usingdirset as follow.




    But this sort implemntation is not working
     
    Santhosh ayiappan
    Ranch Hand
    Posts: 80
    Eclipse IDE Java Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You can have any number of fileset tag within the classpath tag.

    <classpath>
    <fileset dir="${lib.dir1}">
    <include name="*.jar" />
    </fileset>
    <fileset dir="${lib.dir2}">
    <include name="*.jar" />
    </fileset>
    </classpath>
     
    siba swain
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Earlier i had done that way but it made my build file very large.so I thought I will move these directory listing to property file and in build file I will use some loop or macro which will loop throgh these directories and create the build classpath
     
    Peter Johnson
    author
    Bartender
    Posts: 5852
    7
    Android Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To include all of the jar files within a directory and all subdirectories, use "<includes>**/*.jar</includes>".

    By the way, is this a classpath for running or for compiling? For compiling you only need to include the JARs that contain the classes mentioned in your import statements. For example, you might be using commons-logging with log4j. Only the commons-logging JAR is required to be in the classpath at compile time; but at runtime you would need both JARs.
     
    siba swain
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is how I did.

    1. First in build.properties I defined a variable that will list the lib dirs.
    lib.dirs=\
    DAS/lib,\
    DAS-UI/lib,\
    DPS/lib,\
    DSS/lib,\
    DCS/lib,\
    DAF/Search/Index/lib,\
    DAF/Search/Query/lib,\
    DAF/Search/common/lib
    2. Then in build.xmls, compile target I am forming the classpath as below.

    <target name="compile" depends="init" description="Compiles the source code to the build directory.">

    <var name="compile.class.path" value="" /> <!-- Defined a variable with null value -->

    <!-- Loop throgh the list lib.dirs -->
    <for list="${lib.dirs}" param="pathitem" delimiter=",">
    <sequential>
    <var name="compile.class.path" value="${compile.class.path},@{pathitem}/*.jar" />
    </sequential>
    </for>

    Now "compile.class.path" will contain all your jars.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic