1

I am trying to integrate yuicompressor with Ant to automate the minification of our CSS and JS files. However, I keep getting the following error message when I try to run build.xml:

    BUILD FAILED
/Applications/MAMP/htdocs/zanadu-dev/build/build.xml:64: taskdef A class needed by class com.yahoo.platform.yui.compressor.YUICompressTask cannot be found: org/mozilla/javascript/EvaluatorException
 using the classloader AntClassLoader[/usr/share/ant/lib/YUIAnt.jar:/usr/share/ant/lib/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar:/usr/share/ant/lib/yuicompressor-2.4.6/lib/rhino-1.6R7.jar]

Here is the code in my build.xml file:

<target name="minify" depends="build" description="Minifiy CSS and JS files">
    <available file="${antlib.dir}/YUIAnt.jar" property="YUIANT_AVAILABLE" />

    <fail unless="YUIANT_AVAILABLE" message="YUIAnt.jar not found" />

    <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">

        <classpath>
            <pathelement path="${antlib.dir}/YUIAnt.jar" />
            <pathelement path="${antlib.dir}/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar" />
                    <pathelement path="${antlib.dir}/yuicompressor-2.4.6/lib/rhino-1.6R7.jar" />
            </classpath>
        </taskdef>      

        <mkdir dir="${jsminify.dir}" />

        <yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true" 
            outputfolder="${jsmin.dir}">
            <fileset dir="${js.dir}" >
                <include name="**/*.js" />
            </fileset>
        </yuicompress>

        <mkdir dir="${cssminify.dir}" />

        <yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true" 
            outputfolder="${cssmin.dir}">
            <fileset dir="${css.dir}" >
                <include name="**/*.css" />
            </fileset>
        </yuicompress>

  </target>

I have tried following several online examples on this, but all seem to yield the same error message. Not sure exactly where I can find the EvaluatorException class that seems to be missing.

Any idea what I may be doing wrong?

Cheers!

Bug Magnet
  • 2,668
  • 5
  • 29
  • 28

2 Answers2

2

Your taskdef is missing one lib.

<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
    <classpath>
        <pathelement path="${antlib.dir}/YUIAnt.jar" />
        <pathelement path="${antlib.dir}/yuicompressor-2.4.6.jar" />
        <pathelement path="${antlib.dir}/rhino-1.6R7.jar" />
    </classpath>
</taskdef>   

EDIT:,

The problem is somehow related to the jar locations and Ant's class-loader, see this post

One workaround is to copy YUIAnt.jar, yuicompressor-2.4.6.jar and rhino-1.6R7.jar to one directory. Then use it like above. I've tried and it works.

Community
  • 1
  • 1
escrubalo
  • 330
  • 1
  • 6
  • Thanks! But I've added the above line to include rhino, but am still getting an error: BUILD FAILED /Applications/MAMP/htdocs/zanadu-dev/build/build.xml:64: taskdef A class needed by class com.yahoo.platform.yui.compressor.YUICompressTask cannot be found: org/mozilla/javascript/EvaluatorException using the classloader AntClassLoader[/usr/share/ant/lib/YUIAnt.jar:/usr/share/ant/lib/yuicompressor-2.4.6/build/yuicompressor-2.4.6.jar:/usr/share/ant/lib/yuicompressor-2.4.6/lib/rhino-1.6R7.jar] – Bug Magnet Aug 31 '11 at 02:49
1

if you use http://code.google.com/p/yui-compressor-ant-task/ for me solution was to use classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask" instead of classname="com.yahoo.platform.yui.compressor.YUICompressTask"

Sergey
  • 933
  • 2
  • 19
  • 48