Chinaunix首页 | 论坛 | 博客
  • 博客访问: 530506
  • 博文数量: 135
  • 博客积分: 3568
  • 博客等级: 中校
  • 技术积分: 1942
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-19 17:52
文章分类

全部博文(135)

文章存档

2012年(29)

2011年(41)

2010年(26)

2009年(12)

2008年(9)

2007年(12)

2006年(6)

分类: Java

2011-04-29 21:44:54


在ZIP/JAR等命令中如何排除目录
  1. <jar jarfile="${deploy.dir}/${context.name}/${context.name}.war" >
  2.   <fileset dir="./webapps">
  3.     <exclude name="axis2-web/"/> <!-- 把 axis-web 这个目录也删除 -->
  4.     or
  5.     <exclude name="axis2-web/**"/> <!-- 把 axis-web 这个目录也删除,作用同上 -->
  6.     or
  7.     <exclude name="axis2-web/**/*"/> <!-- 仅把 axis-web 中的内容删除,但是保留这个空目录 -->
  8.   </fileset>

  9.  
       
     

  10. </jar>

常用的Jar工程和War工程的ant脚本
 ant.zip  

Jar工程

build.properties
  1. # 工程目录结构
  2. # XXYYZZ/ant/build.properties
  3. # XXYYZZ/ant/build.xml
  4. # XXYYZZ/classes
  5. # XXYYZZ/deploy
  6. # XXYYZZ/doc
  7. # XXYYZZ/lib/*.jar
  8. # XXYYZZ/sources/../*.java
  9. # XXYYZZ/test/lib/*.jar
  10. # XXYYZZ/test/sources/*.java

  11. # 工程的名称
  12. context.name=XXYYZZ

  13. # 工程的版本
  14. project.version=1.0.0

  15. # 源代码所在路径
  16. sources.dir=./sources

  17. # 编译目录
  18. classes.dir=./classes

  19. # 类库目录
  20. lib.dir=./lib

  21. # WAR部署路径
  22. deploy.dir=./deploy
build.xml
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- ======================================================================
  3.    - 工程的 ant 编译脚本
  4.      ====================================================================== -->
  5. <project name="XXYYZZ" default="deploy" basedir="..">

  6.   <!-- 读入配置文件 -->
  7.   <property file="./ant/build.properties" />

  8.   <!-- 设定classpath -->
  9.   <path id="classpath.lib">
  10.     <fileset dir="${lib.dir}">
  11.       <include name="*.jar"/>
  12.     </fileset>
  13.   </path>

  14.   <!-- =================================
  15.      - 清空工作目录
  16.        ================================= -->
  17.   <target name="clean" description="清空工作目录">
  18.     <delete dir="${deploy.dir}" />
  19.     <mkdir dir="${deploy.dir}/${context.name}/lib" />
  20.     <delete includeEmptyDirs="true" >
  21.       <fileset dir="${classes.dir}" includes="**/*" />
  22.     </delete>
  23.   </target>

  24.   <!-- =================================
  25.      - 编译、打包
  26.        ================================= -->
  27.   <target name="compile" depends="clean" description="编译、打包">

  28.     <!-- *.java -> *.class -->
  29.     <javac srcdir="${sources.dir}"
  30.            destdir="${classes.dir}"
  31.            classpathref="classpath.lib"
  32.            debug="on"
  33.            encoding="GBK"
  34.            source="1.6"
  35.            target="1.6" />

  36.     <!-- native2ascii -->
  37.     <native2ascii src="${sources.dir}"
  38.                   dest="./classes"
  39.                   includes="*.properties"
  40.                   ext=".properties"
  41.                   encoding="GBK" />

  42.     <!-- 复制其他资源文件 -->
  43.     <copy todir="${classes.dir}">
  44.       <fileset dir="${sources.dir}">
  45.         <exclude name="**/*.java"/>
  46.         <exclude name="**/*.properties"/>
  47.       </fileset>
  48.     </copy>

  49.     <!-- 打包 -->
  50.     <jar jarfile="${deploy.dir}/${context.name}/${context.name}.jar"
  51.          basedir="${classes.dir}" />
  52.   </target>

  53.   <!-- =================================
  54.      - 部署
  55.        ================================= -->
  56.   <target name="deploy" depends="compile" description="部署">

  57.     <!-- 类库 -->
  58.     <copy todir="${deploy.dir}/${context.name}/lib" >
  59.       <fileset dir="${lib.dir}"/>
  60.     </copy>

  61.     <!-- 配置文件 -->
  62.     <copy todir="${deploy.dir}/${context.name}" includeEmptyDirs="false">
  63.       <fileset dir=".">
  64.         <include name="*"/>
  65.         <exclude name=".*"/>
  66.       </fileset>
  67.     </copy>

  68.     <!-- 执行脚本 -->
  69.     <path id="work.path">
  70.        <pathelement location="${deploy.dir}/${context.name}" />
  71.     </path>
  72.     <path id="run.classpath.lib">
  73.       <fileset dir="${deploy.dir}/${context.name}/lib">
  74.         <include name="*.jar"/>
  75.       </fileset>
  76.     </path>
  77.     
  78.     <!-- unix -->
  79.     <pathconvert property="work.absolute.path.unix"
  80.                  refid="work.path"
  81.                  targetos="unix"/>
  82.     <pathconvert property="cp.unix"
  83.                  refid="run.classpath.lib"
  84.                  targetos="unix" >
  85.       <map from="${work.absolute.path.unix}" to="."/>
  86.     </pathconvert>
  87.     <pathconvert property="run.classpath.path.unix"
  88.                  refid="run.classpath.lib"
  89.                  targetos="unix"/>
  90.     <echo file="${deploy.dir}/${context.name}/${context.name}.sh" >#!/bin/bash
  91.       java -classpath .:${context.name}.jar:${run.classpath.path.unix} u.test.XxxMain
  92.     </echo>

  93.     <!-- windows -->
  94.     <pathconvert property="work.absolute.path.windows"
  95.                  refid="work.path"
  96.                  targetos="windows" />
  97.     <pathconvert property="cp.windows"
  98.                  refid="run.classpath.lib"
  99.                  targetos="windows" >
  100.       <map from="${work.absolute.path.windows}" to="."/>
  101.     </pathconvert>
  102.     <pathconvert property="run.classpath.path.windows"
  103.                  refid="run.classpath.lib"
  104.                  targetos="windows" />
  105.     <echo file="${deploy.dir}/${context.name}/${context.name}.bat" >
  106.       @echo off
  107.       java -classpath .;${context.name}.jar;${cp.windows} u.test.XxxMain
  108.       @pause
  109.     </echo>

  110.     <zip destfile="${deploy.dir}/${context.name}.zip"
  111.          basedir="${deploy.dir}/${context.name}" />
  112.   </target>

  113.   <!-- =================================
  114.      - 生成JavaDoc
  115.        ================================= -->
  116.   <target name="javadoc" description="生成JavaDoc">
  117.     <delete dir="${doc.dir}/javadoc" />
  118.     <mkdir dir="${doc.dir}/javadoc" />
  119.     <javadoc classpathref="classpath.lib"
  120.              sourcepath="${sources.dir}"
  121.              destdir="${doc.dir}/javadoc"
  122.              doctitle="${context.name}"
  123.              windowtitle="${context.name}"
  124.              use="true"
  125.              splitindex="true"
  126.              encoding="GBK"
  127.              private="false"
  128.              packagenames="**/*">
  129.     </javadoc>
  130.   </target>
  131. </project>


War工程

build.properties
  1. # 工程目录结构
  2. # XXYYZZ/ant/build.properties
  3. # XXYYZZ/ant/build.xml
  4. # XXYYZZ/deploy
  5. # XXYYZZ/doc
  6. # XXYYZZ/webapps/WEB-INF/classes
  7. # XXYYZZ/webapps/WEB-INF/lib/*.jar
  8. # XXYYZZ/sources/../*.java
  9. # XXYYZZ/test/lib/*.jar
  10. # XXYYZZ/test/sources/*.java

  11. # 工程的名称
  12. context.name=XXYYZZ

  13. # 工程的版本
  14. project.version=1.0.0

  15. # 源代码所在路径
  16. sources.dir=./sources

  17. # 编译目录
  18. classes.dir=./classes

  19. # Web根目录
  20. web.dir=./webapps/WEB-INF

  21. # jar包目录
  22. lib.dir=./webapps/WEB-INF/lib

  23. # Web服务器的lib目录的路径
  24. webapsvr.lib.dir=D:/dev/apache-tomcat-6.0.29/lib

  25. # WAR部署路径
  26. deploy.dir=./deploy

  27. # Doc目录
  28. doc.dir=./doc

build.xml
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- ======================================================================
  3.    - 工程的 ant 编译脚本
  4.      ====================================================================== -->
  5. <project name="XXYYZZ" default="deploy" basedir="..">

  6.   <!-- 读入配置文件 -->
  7.   <property file="./ant/build.properties" />
  8.   <property file="./sources/system.properties" />

  9.   <!-- 设定classpath -->
  10.   <path id="classpath.lib">
  11.     <fileset dir="${lib.dir}">
  12.       <include name="*.jar" />
  13.     </fileset>
  14.     <fileset dir="${webapsvr.lib.dir}">
  15.       <include name="*.jar" />
  16.     </fileset>
  17.   </path>

  18.   <!-- =================================
  19.      - 清空工作目录
  20.        ================================= -->
  21.   <target name="clean" description="清空工作目录">
  22.     <delete dir="${deploy.dir}" failonerror="true"/>
  23.     <mkdir dir="${deploy.dir}/${context.name}" />
  24.     <delete includeEmptyDirs="true" failonerror="true">
  25.       <fileset dir="${classes.dir}" includes="**/*" />
  26.     </delete>
  27.   </target>
  28.  
  29.   <!-- =================================
  30.        - 编译 、打包
  31.        ================================= -->
  32.   <target name="compile" depends="clean" description="编译 、打包">
  33.     
  34.     <!-- *.java -> *.class -->
  35.     <javac srcdir="${sources.dir}"
  36.            destdir="${classes.dir}"
  37.            classpathref="classpath.lib"
  38.            encoding="GBK"
  39.            source="1.6"
  40.            target="1.6"
  41.            debug="on" >
  42.     </javac>

  43.     <!-- native2ascii -->
  44.     <native2ascii src="${sources.dir}"
  45.                   dest="${classes.dir}"
  46.                   includes="*.properties"
  47.                   ext=".properties"
  48.                   encoding="GBK" />

  49.     <!-- 复制其他资源文件 -->
  50.     <copy todir="${classes.dir}">
  51.       <fileset dir="${sources.dir}">
  52.         <exclude name="**/*.java"/>
  53.         <exclude name="**/*.properties"/>
  54.       </fileset>
  55.     </copy>
  56.      
  57.     <!-- 打包 -->
  58.     <jar jarfile="${deploy.dir}/${context.name}/${context.name}.war" >
  59.       <fileset dir="${web.dir}">
  60.         <exclude name="axis2-web/"/>
  61.       </fileset>
  62.     </jar>
  63.   </target>

  64.   <!-- =================================
  65.        - 部署
  66.        ================================= -->
  67.   <target name="deploy" depends="compile" description="部署">

  68.   </target>

  69.   <!-- =================================
  70.      - 生成JavaDoc
  71.        ================================= -->
  72.   <target name="javadoc" description="生成JavaDoc">
  73.     <delete dir="${doc.dir}/javadoc" />
  74.     <mkdir dir="${doc.dir}/javadoc" />
  75.     <javadoc classpathref="classpath.lib"
  76.              sourcepath="${sources.dir}"
  77.              destdir="${doc.dir}/javadoc"
  78.              doctitle="${context.name}"
  79.              windowtitle="${context.name}"
  80.              use="true"
  81.              splitindex="true"
  82.              encoding="GBK"
  83.              private="true"
  84.              packagenames="**/*">
  85.     </javadoc>
  86.   </target>
  87. </project>

使用 war 打包

点击(此处)折叠或打开

  1. <!-- 打包 -->
  2.     <war destfile="${deploy.dir}/${context.name}/${context.name}.war"
  3.          webxml="${web.dir}/web.xml"
  4.          encoding="UTF-8">
  5.       <fileset dir="./webapps">
  6.         <exclude name="axis2-web/"/>
  7.       </fileset>
  8.     </war>
  9.   </target>




阅读(984) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~