使用ant和YUI Compressor压缩js css

用到两个jar包
YUIAnt.jar  下载地址 http://www.ubik-ingenierie.com/miscellanous/YUIAnt/
yuicompressor-2.4.2.jar 下载地址 http://www.julienlecomte.net/yuicompressor/

ant的够建脚本

<property name="context" value="${basedir}\context"/>
	<path id="yuiClasspath">
		<fileset dir="${webinf}/lib">
			<include name="yuicompressor-2.4.2.jar"/>
			<include name="YUIAnt.jar"/>
		</fileset>
	</path>

	<target name="compres-js-css" description="压缩 js css 文件">
		<taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
			<classpath>
				<path refid="yuiClasspath"/>
			</classpath>
		</taskdef>
		<yuicompress linebreak="300" warn="false" munge="yes" 
			preserveallsemicolons="true" outputfolder="${context}">
			<fileset dir="${context}">
				<include name="js/**/*.js" />
				<include name="lib/**/*.js"/>
                                <include name="fckeditor/**/*.js"/>
				<include name="css/**/*.css"/>
				<include name="lib/**/*.css"/>
                                <include name="fckeditor/**/*.css"/>
			</fileset>
		</yuicompress>
	</target>


运行ant后回将原来的js和css覆盖掉
如果不想覆盖 可以设置outputfolder

你可能感兴趣的:(apache,xml,ant,css,yui)