java - 设置 ant 任务来缩小 javascript 文件时遇到问题

标签 java javascript ant yui

我在 Netbeans 7.1.2 和 Ant 1.8.2 中使用 YUI 压缩机作为 Ant 任务时遇到问题。

运行“minify”ant 目标时出现以下错误:

taskdef class net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask cannot be found using the classloader AntClassLoader[]

缩小 ant 目标如下所示:

<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”存在,这就是为什么我上面得到的错误没有意义。

是否有某种 Ant Library 主目录需要我添加 jar 文件?目前,我只是像大多数项目一样将它们添加到正常的 Netbeans 类路径中。我猜 Ant Runtime 完全使用了不同的库路径?

最佳答案

来自Running Apache Ant :

Additional directories to be searched may be added by using the -lib option. The -lib option specifies a search path. Any jars or classes in the directories of the path will be added to Ant's classloader. The order in which jars are added to the classpath is as follows:

  • -lib jars in the order specified by the -lib elements on the command line
  • jars from ${user.home}/.ant/lib (unless -nouserlib is set)
  • jars from ANT_HOME/lib

关于java - 设置 ant 任务来缩小 javascript 文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13813682/

相关文章:

java - 在众多依赖项中优先选择最新的 jar (java)

java - 为什么在转换为 XML 时对 JSON 内容属性进行特殊处理?

java - Firefox Profile 无法自动下载文件

java - Gradle、rt.jar访问限制

javascript - 如何从嵌套的每个数组中删除公共(public)属性

javascript - react componentdidupdate 引发无限循环

java - 在 Play (Scala) 中使用 Guice 注释

javascript - 如何将谷歌地理定位的坐标传递给另一个函数?

java - Ant中的"Unable to find a javac compiler"错误

java - GWT 2.8 编译器警告