failed to compress javascript files using yuicompressor

579 views Asked by At

I have an ant file which contains a task to compress certain js files. I am using yui compressor to compress my files. So I have defined the taskdef

<taskdef resource="yuicompressor.tasks" classpath="lib/yuicompressor-taskdef-1.0.jar;lib/yuicompressor-2.4.2.jar" />

and this is how I am using yui compressor ant task

<yuicompressor todir="./js/" verbose="true">
    <fileset dir="./js/" 
        includes="**/*.js"> 
    </fileset>
    <mapper type="glob" from="*.js" to="*.js" />
</yuicompressor>

When I run this ant file directly it works fine, that is all js files get compressed.

But when I run this ant file from pom.xml then it shows

Failed to compress files file_name.js

This is my execution task in pom.xml

<execution>
    <id>default</id>
    <phase>generate-sources</phase>
    <configuration>
        <tasks>
            <tstamp />
            <ant antfile="build.xml" />
        </tasks>
    </configuration>
    <goals>
        <goal>run</goal>
    </goals>
</execution>

What could be the possible issue?

1

There are 1 answers

0
Sunil Garg On BEST ANSWER

In my case I was using the relative path in yuicompressor

<yuicompressor todir="./js/" verbose="true">
    <fileset dir="./js/" 
        includes="**/*.js"> 
    </fileset>
    <mapper type="glob" from="*.js" to="*.js" />
</yuicompressor>

I updated to

<yuicompressor todir="${basedir}/js/" verbose="true">
    <fileset dir="${basedir}/js/" 
        includes="**/*.js"> 
    </fileset>
    <mapper type="glob" from="*.js" to="*.js" />
</yuicompressor>

And working perfectly fine!!