jQuery in Action, 2nd edition*
The moose likes Ant, Maven and Other Build Tools and the fly likes classpath setup by taking jars from multiple directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "classpath setup by taking jars from multiple directory" Watch "classpath setup by taking jars from multiple directory" New topic
Author

classpath setup by taking jars from multiple directory

siba swain
Greenhorn

Joined: Jul 04, 2011
Posts: 10
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

Joined: Jan 30, 2007
Posts: 80

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

Joined: Jul 04, 2011
Posts: 10
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

    Joined: Jan 30, 2007
    Posts: 80

    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

    Joined: Jul 04, 2011
    Posts: 10
    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

    Joined: May 14, 2008
    Posts: 5837
        
        7

    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.


    JBoss In Action
    siba swain
    Greenhorn

    Joined: Jul 04, 2011
    Posts: 10
    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.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: classpath setup by taking jars from multiple directory