毕设中ant遇到的各种问题

          由于毕设中前端JS的库是我自己写的,当时用到了一些工具,如yuicompressor,jsTestDriver等等,所以顺便也使用ant去部署前端的应用了。

          在ant中,遇到问题的地方在于CSS和JS的压缩,由于CSS压缩采用了yui compressor,JS压缩采用了googleclosurecompiler,我对ant中怎么集成它们不是很熟,所以遇到了一点问题。

          首先是CSS的压缩,最开始的时候一直报: java.io.FileNotFoundException: I:\code\Current-Coding\beauty\code\beauty-static\css\build\global-min.css (系统找不到指的文件。)

          这个问题纠结了我好长时间,终于今天搞定了,直接贴代码吧:


<target name = "minifyCss" depends="copyToBuild">
		<!--
		yui compressor使用如下:
		java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js
		-->
		<echo>begin to minify css:</echo>
		<apply executable = "java" verbose = "true" dest = "${toper.build.dir}" failonerror = "true" parallel = "false">
			<fileset dir = "${toper.build.dir}" includes = "**/*.css" />
			<arg line = "-jar" />
			<arg path="${toper.tools.dir}/yuicompressor.jar" />
			<arg line = "--charset utf8" />
			<srcfile />
			<arg value = "--type" />
			<arg value = "css" />
			<arg value = "-o" />
			<targetfile />
			<mapper type = "glob" from = "*.css" to = "*-min.css" />
		</apply>
	</target>
          这个是我最终的配置项,最开始的这个问题在于没有指定srcfile,然后每次它都会去找targetfile,也就是xx-min.css,而这个文件是不存在的,所以就抛出异常了。


         srcfile没问题之后,后面遇到了一个压缩始终只能压缩一个文件的问题,经各种debug,终于发现要把parallel的值设为false,原来我的值为true.

          压缩JS的配置项为:


<target name = "minifyJs" depends="copyToBuild">
		<!--google closure compiler的使用如:
				java -jar compiler.jar
				\\-\\-js hello.js \\-\\-js_output_file hello-compiled.js
		-->
		<apply executable="java" dest = "${toper.build.dir}">
			<fileset dir = "${toper.build.dir}" includes="**/*.js" />
			<arg line = "-jar" />
			<arg path = "${toper.tools.dir}/googleclosurecompiler.jar" />
			<arg value = "--js" />
			<srcfile />
			<arg value = "--js_output_file" />
			<targetfile />
			<mapper type = "glob" from = "*.js" to = "*-min.js" />
		</apply>
	</target>
        之前的问题是没有指定<arg value = "--js" /><srcfile/>,也就是说和css的问题是一样的。



转载于:https://my.oschina.net/mingtingling/blog/123054

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值