Ant and yuicompressor
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}" >
开发者_JS百科 <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!
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.
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"
精彩评论