Minified JavaScript/CSS Builds
How to include minified JavaScript and CSS files in web application builds In NetBeans IDE? Here's a solution.
I
have adapted the work done by Philippe Mouawad and Andrew Gomilko using the YUI Compression tool as Ant Task so that it can be used with NetBeans 6.1 web application projects.
To get automated JavaScript and CSS files into your WAR files during the NetBeans build process do the following:
- Download the YUI Compression Lib making sure you abide by the terms of the licence agreement.
- Download the YUIAnt.jar , this is the ant task required, see this page for information.
These two files need to go in your NetBeans ant\lib folder, for my Windows/NetBeans 6.1 installation that is:
C:\Program Files\NetBeans 6.1\java2\ant\lib
For web applications that you want to build with the compressed js/css files, add the following XML to the build.xml for the project, overriding the "-pre-dist" Ant target, which is not currently configured by default in NetBeans.
<target name="-pre-dist">
<echo level="info" message="Compressing JavaScript and CSS files...." />
<path id="yuicompressor.classpath">
<fileset dir="${ant.home}/lib">
<include name="yuicompressor-2.3.5.jar"/>
</fileset>
</path>
<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<path refid="yuicompressor.classpath"/>
</classpath>
</taskdef>
<yuicompress linebreak="8000" warn="false" munge="no" preserveallsemicolons="true"
outputfolder="${basedir}/${build.web.dir}" >
<fileset dir="${basedir}/web" excludes="/ext-2.1/**/*.js" >
<include name="**/*.js" />
<include name="**/*.css" />
</fileset>
</yuicompress>
<echo level="info" message="Compression Complete" />
</target>
This
will compress and copy the JavaScript and CSS files to the build directory
before the WAR file is built and will thus be included in your WAR file.
Note
there is a line in my example with an "exclude" for my ext-2.1
directory, the files there are already compressed so I have excluded
them, just add/remove to suit your application.
All
we need now is for someone to code a NetBeans plugin that configures
this all for us and makes it configurable from a wizard maybe, any
takers?
- Login or register to post comments
- 1620 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Michael Henke replied on Mon, 2008/06/30 - 11:42am
Looks fairly familar, except I replace the orginal js/css files with the minified versions.
Minify CSS/JS ant revisited using YUI compressor - http://tinyurl.com/5agqw3