0

I want to use ant for js and css minification at time of building the project. Please find below directory structure of my project:

directory structure

Here, scripts directory has multiple directories. I want to exclude directory named "Libraries" in scripts dirctory from ant task.

The dirctories other than "Libraries" has js files. And I want to include these js files in ant minification task.

Please find below my build.xml:

<project name="ITV" default="doMinification">
    <property name="webroot.dir" value="webapp/" /> 
    <target name="doMinification" depends="minifyjs" />

    <tstamp>
        <format property="TODAY_MY" pattern="yyyyMMdd-HHmmss"  locale="en,UK" />
    </tstamp>

    <!-- Minify JS -->
    <target name="minifyjs">                
        <apply executable="java" parallel="false" dest="webapp/scripts/" verbose="true">
            <fileset id="jsFiles" dir="webapp/scripts/">
                <exclude name="webapp/scripts/Libraries/" />                
                <include name="**/*.js"/>                   
            </fileset>
            <arg line="-jar"/>
            <arg path="yuicompressor-2.4.7.jar"/>
            <srcfile/>
            <arg line="-o"/>
            <mapper type="glob" from="**/*.js" to="*-min-${TODAY_MY}.js" />
            <targetfile/>
        </apply>            
    </target>
</project>

How to exclude a specific directory and include other directories with its files in ant javascript minification task ?

Valay
  • 1,991
  • 2
  • 43
  • 98

1 Answers1

0

You may want to check similar question here

There is this answer:

<exclude name="**/dir_name_to_exclude/**" />

For your case:

<exclude name="**/Libraries/**" />

eg:

 <target name="minifyjs">                
        <apply executable="java" parallel="false" dest="webapp/scripts/" verbose="true">
            <fileset id="jsFiles" dir="webapp/scripts/">
                <exclude name="**/Libraries/**" />                
                <include name="**/*.js"/>                   
            </fileset>
            <arg line="-jar"/>
            <arg path="yuicompressor-2.4.7.jar"/>
            <srcfile/>
            <arg line="-o"/>
            <mapper type="glob" from="**/*.js" to="*-min-${TODAY_MY}.js" />
            <targetfile/>
        </apply>            
    </target>

I hope this helps.

Community
  • 1
  • 1
CodeLama
  • 94
  • 5