码迷,mamicode.com
首页 > 其他好文 > 详细

打包工具开发随记

时间:2015-01-20 20:12:25      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

package sample;

import java.io.IOException;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class Sample2 {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws JDOMException 
	 */
	public static void main(String[] args) throws JDOMException, IOException {
		// TODO Auto-generated method stub
		SAXBuilder sb=new SAXBuilder();
		Document doc=sb.build("zip.xml");
		Element root =doc.getRootElement();
		List<Element> lst=root.getChildren("property");
		for(Element el :lst)
		{
			if(el.getAttributeValue("name").equals("mubiaowenjian"))
				el.setAttribute("value", "sunzekun");
		}//找寻属性名name为mulu的子元素   修改value属性 
		SaveXml.saveXML(doc);
		Runtime.getRuntime().exec("cmd /k ant -f zip.xml");
		//通过ant执行build.xml
		System.out.println("chenggong");
	}
	
}

 

 

 

package sample;

import java.io.FileWriter;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class SaveXml {
	public static void saveXML(Document doc) throws IOException{
		XMLOutputter xmlopt=new XMLOutputter();
		//创建xml文件输出流
		FileWriter writer= new FileWriter("zip.xml");
		//构建输出对象到zip.xml
		Format fm = Format.getPrettyFormat();
		xmlopt.setFormat(fm);
		//指定文档格式
		xmlopt.output(doc, writer);
		//将doc写入到指定的文件夹中
		writer.close();
	}
}

 

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="compress" default="zip">
<property name="mulu" value="e:/ant+jdom/xutianhao"/>
<property name="mubiaowenjian" value="xutianhao"/>
<target name="zip">
	<zip destfile="${mubiaowenjian}.zip"
		basedir="${mulu}"
	/>	
</target>
</project>

 

打包工具开发随记

标签:

原文地址:http://www.cnblogs.com/tianhao/p/4236942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!