Saturday, 8 November 2008

Updated - Minified Javascript and CSS files in netbeans

If you want automated minified javascript and css files in your netbeans generated war files during the build process do the following :-
These two files need to go in your netbeans ant\lib folder, for my windows/netbeans 6.5 installation thats C:\Program Files\NetBeans 6.5\java2\ant\lib.

For web applications that you want to build with compressed js/css files add the folloing xml to the build.xml for the project, overiding the "-pre-dist" ant target which is not currently configured by default in netbeans.

<target name="-pre-dist" >
<condition property="">
<istrue value="${}"/>
<antcall target="-do-compression"/>
<target name="-do-compression" unless="" >
<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"/>
<taskdef name="yuicompress" classname="" >
<path refid="yuicompressor.classpath"/>
<yuicompress linebreak="16000" warn="false" munge="no" preserveallsemicolons="true"
outputfolder="${basedir}/${build.web.dir}" >
<fileset dir="${basedir}/web" excludes="**/ext-2.2/**/*.js" >
<include name="**/*.js" />
<include name="**/*.css" />
<echo level="info" message="Compression Complete" />

On the line that includes <include name="yuicompressor-x.x.x.jar"/>
replace the x's with the version of the library you are using.

Then set your includes and excludes as per the example above.

This works for netbeans versions 6.1 onwards including 6.5.

Compression only takes place if client side debugging is configured off.