user1068636
user1068636

Reputation: 1939

Trouble setting up a an ant task to minify javascript file

I am having trouble using YUI Compressor as an Ant Task within Netbeans 7.1.2 and Ant 1.8.2.

When running "minify" ant target I get the following error:

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

The minify ant target looks like:

<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>

My Netbeans "project.properties" file looks like

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}

Also, I tried the following:

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

Which obvious proves that "YuiCompressorTask.class" exists, which is why the error I'm getting above does not make sense.

Is there some kind of Ant Library home I need to add the jar files to? Currently I'm just adding them to the normal Netbeans classpath like most projects. I'm guessing Ant Runtime uses a different library path altogether?

Upvotes: 1

Views: 1886

Answers (1)

Alex
Alex

Reputation: 11090

From 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

Upvotes: 1

Related Questions