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

打包工具开发随记

时间:2015-01-21 19:50:23      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

zip.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="compress" default="zip">
  <property name="mulu" value="e:/XTH_caozuo/ant+jdom/new" />
  <property name="mubiaowenjian" value="e:/XTH_caozuo/ant+jdom/new/sunzekun" />
  <target name="zip">
    <zip destfile="${mubiaowenjian}.zip" >
    <fileset dir="${mulu}">
    	<include name="**/*.txt"/>
    </fileset>
    </zip>
  </target>
</project>

 

unzip.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="compress" default="zip">
  <property name="jieyamulu" value="e://XTH_caozuo/ant+jdom/new" />
  <property name="jieyawenjian" value="d://xutianhao_caozuo/sunzekun.zip" />
  <target name="zip">
    <unzip src="${jieyawenjian}" dest="${jieyamulu}" />
  </target>
</project>

 

zip.java

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 
	 */
	//文件zip打包 
	
	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", "d://sunzekun");
		}//找寻属性名name为目标文件的子元素   修改value属性 
		SaveXml.saveXML(doc);
		Runtime.getRuntime().exec("cmd /k ant -f zip.xml");
		//通过在cmd执行ant命令执行build.xml
		System.out.println("chenggong");
	}
	
}

 

 

unzip.java

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 Unzip {

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

 

打包工具开发随记

标签:

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

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