我在 Netbeans 7.1.2 和 Ant 1.8.2 中使用 YUI Compressor 作为 Ant 任务时遇到问题。
运行“缩小”蚂蚁目标时,出现以下错误:
taskdef class net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask cannot be found using the classloader AntClassLoader[]
缩小蚂蚁目标看起来像:
<target name="minify">
<!--${libs} is path to the downloaded jars -->
<property
name="yui-compressor.jar"
location="${file.reference.yuicompressor-2.4.2.jar}" />
<property
name="yui-compressor-ant-task.jar"
location="${file.reference.yui-compressor-ant-task-0.5.jar}" />
<property
name="YUIAnt.jar"
location="${file.reference.YUIAnt.jar}" />
<path id="task.classpath">
<pathelement location="${yui-compressor.jar}" />
<pathelement location="${yui-compressor-ant-task.jar}" />
<pathelement location="${YUIAnt.jar}" />
</path>
<!-- yui-compressor task definition -->
<taskdef
name="yui-compressor"
classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
<classpath refid="task.classpath" />
</taskdef>
<!-- invoke compressor -->
<yui-compressor warn="false" charset="UTF-8" fromdir="${build.dir}" todir="${build.dir}">
<include name="/Projects/netbeans/testproj/src/resources/insert-image-dialog.js" />
<include name="/Projects/netbeans/testproj/src/resources/anotherjs.js" />
</yui-compressor>
</target>
我的 Netbeans “project.properties”文件看起来像
dist.dir=dist
dist.jar=${dist.dir}/Dec102012.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.yui-compressor-ant-task-0.5.jar=/Users/someuser/Downloads/yui-compressor-ant-task-0.5/bin/yui-compressor-ant-task-0.5.jar
file.reference.YUIAnt.jar=/Users/someuser/Downloads/YUIAnt.jar
file.reference.yuicompressor2.4.2.jar=/Users/someuser/Downloads/builder/componentbuild/lib/yuicompressor/yuicompressor-2.4.2.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.yuicompressor-2.4.2.jar}:\
${file.reference.yui-compressor-ant-task-0.5.jar}:\
${file.reference.YUIAnt.jar}
另外,我尝试了以下方法:
jar -tvf yui-compressor-ant-task-0.5.jar
0 Thu Feb 25 02:15:32 EST 2010 META-INF/
102 Thu Feb 25 02:15:30 EST 2010 META-INF/MANIFEST.MF
0 Thu Feb 25 02:15:30 EST 2010 net/
0 Thu Feb 25 02:15:30 EST 2010 net/noha/
0 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/
0 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/
0 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/
0 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/tasks/
2993 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/tasks/CompressionStatistics.class
1611 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/tasks/FileType.class
2141 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/tasks/YuiCompressorTask$1.class
7265 Thu Feb 25 02:15:30 EST 2010 net/noha/tools/ant/yuicompressor/tasks/YuiCompressorTask.class
175 Thu Feb 25 02:15:30 EST 2010 META-INF/INDEX.LIST
这显然证明了“YuiCompressorTask.class”的存在,这就是为什么我上面的错误没有意义。
我需要将 jar 文件添加到某种 Ant 库主页吗?目前我只是像大多数项目一样将它们添加到普通的 Netbeans 类路径中。我猜 Ant Runtime 完全使用了不同的库路径?