ANT 打 war包,jar包

http://hi.baidu.com/dancemachine/blog/item/e949520e74f096c87bcbe115.html

http://blog.csdn.net/ln831015/archive/2007/08/13/1740869.aspx

 

转)用Ant打war包Build.xml全攻略

2007年07月05日 星期四 上午 09:52

<project basedir="." default="usage" name="myceaas">

<target name="init">


   <property name="Name" value="myceaas" />
   <property name="name" value="myceaas" />
   <property name="version" value="0.2" />
   <property name="year" value="2006" />


   <echo message="----------- ${Name} ${version} [${year}] ------------" />


   <property name="debug" value="off" />
   <property name="optimize" value="on" />
   <property name="deprecation" value="on" />


   <!--<property name="mycedatasycn.location" value="D:/project/myce/mycedatasycn" />-->


<!--    java源文件路径 -->

   <property name="src.dir" value="${basedir}/src" />


<!--    jar包路径 -->
   <property name="lib.dir" value="${basedir}/myceaas/WEB-INF/lib" />


<!--    webapp路径 -->
   <property name="webapp.dir" value="${basedir}/myceaas" />
   <property name="packages" value="com.ce.myceaas.*" />


<!--    准备源文件路径 -->
   <property name="build.src" value="${basedir}/AntBuild/build" />


<!--    编译源文件路径 -->
   <property name="build.dest" value="${basedir}/AntBuild/bin" />


<!--    准备webapp文件路径 -->
   <property name="buildwar.dest" value="${basedir}/AntBuild/warsrc" />


<!--    准备javadoc文件路径 -->
   <property name="build.javadocs" value="${basedir}/AntBuild/doc" />


<!--    打包jar文件路径 -->
   <property name="jar.dest" value="${basedir}/AntBuild/jar" />


<!--    打包war文件路径 -->
   <property name="war.dest" value="${basedir}/AntBuild/war" />
  
   <!--    resin-home路径 -->
   <property name="resin.home" value="C:\resin-pro-3.0.17"/>


<!--    tomcat-home路径 -->
   <property name="tomcat.home" value="C:\tomcat5.5.12"/>
   <property name="j2eelib.dir" value="C:/Program Files/MyEclipse/eclipse/plugins/com.genuitec.eclipse.j2eedt.core_3.9.210/data/libraryset/1.4" />


<!--    classpath -->
   <path id="classpath">
   
    <fileset dir="${j2eelib.dir}">
     <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${lib.dir}">
     <include name="**/*.jar"/>
    </fileset>
    <!--<pathelement location="lib/"/>-->
   </path>


   <filter token="year" value="${year}" />
   <filter token="version" value="${version}" />
   <filter token="date" value="${TODAY}" />
   <filter token="log" value="true" />
   <filter token="verbose" value="true" />


</target>


   <!-- =================================================================== -->
<!-- Help on usage -->
<!-- =================================================================== -->
<target name="usage" depends="init">
   <echo message="${Name} Build file" />
   <echo message="-------------------------------------------------------------" />
   <echo message="" />
   <echo message=" available targets are:" />
   <echo message="" />
   <echo message=" jar --> generates the ${name}.jar file" />
   <echo message=" build --> compiles the source code" />
   <echo message=" javadoc --> generates the API documentation" />
   <echo message=" clean --> cleans up the directory" />
   <echo message="" />
   <echo message=" Please rename build.properties.default to build.properties" />
   <echo message=" and edit build.properties to specify JSDK 2.3 classpath." />
   <echo message="" />
   <echo message=" See the comments inside the build.xml file for more details." />
   <echo message="-------------------------------------------------------------" />
   <echo message="" />
   <echo message="" />
</target>


<!-- =================================================================== -->
<!-- 准备源文件-->
<!-- =================================================================== -->
<target name="prepare-src" depends="init">
   <!-- create directories -->
   <mkdir dir="${build.src}" />
   <mkdir dir="${build.dest}" />
   <mkdir dir="${jar.dest}" />
   <mkdir dir="${war.dest}" />
   <mkdir dir="${buildwar.dest}" />
  
  
   <!-- copy src files -->
   <copy todir="${build.src}">
    <fileset dir="${src.dir}" />
   </copy>
   <copy todir="${buildwar.dest}">
    <fileset dir="${webapp.dir}" />
   </copy>

</target>


<!-- =================================================================== -->
<!-- 编译源文件-->
<!-- =================================================================== -->
<target name="build" depends="prepare-src">
   <javac srcdir="${build.src}" destdir="${buildwar.dest}/WEB-INF/classes" debug="${debug}" optimize="${optimize}">
    <classpath refid="classpath" />
   </javac>
   <copy todir="${buildwar.dest}/WEB-INF/classes">
    <fileset dir="${build.src}" >
     <include name="**/*.xml"/>
    </fileset>
   </copy>
</target>


<!-- =================================================================== -->
<!-- 打war包-->
<!-- =================================================================== -->

<target name="myceaas.war" depends="build">
   <war warfile="${war.dest}/myceaas.war" webxml="${buildwar.dest}/WEB-INF/web.xml">
    <lib dir="${buildwar.dest}/WEB-INF/lib"/>
    <classes dir = "${buildwar.dest}/WEB-INF/classes"/>
    <fileset dir="${buildwar.dest}">
    </fileset>
   </war>

</target>


<!-- =================================================================== -->
<!-- 发布到本的resin和tomcat-->
<!-- =================================================================== -->

<target name="publish" depends="myceaas.war,clean">
   <copy todir="${resin.home}/webapps">
    <fileset dir="${war.dest}" >
     <include name="**/*.war"/>
    </fileset>
   </copy>
   <copy todir="${tomcat.home}/webapps">
    <fileset dir="${war.dest}" >
     <include name="**/*.war"/>
    </fileset>
   </copy>
  
</target>
<!--
<target name="SyncMain">
          <java classname="com.ce.synchronization.main.SyncMain" failonerror="true" fork="yes">
              <classpath refid="classpath"/>
          </java>
</target>
-->
<!-- =================================================================== -->
<!-- 产生javadoc api 文档-->
<!-- =================================================================== -->
<target name="javadoc" depends="build">
   <mkdir dir="${build.javadocs}" />
   <javadoc packagenames="${packages}" sourcepath="${build.src}" destdir="${build.javadocs}" author="true" version="true" use="true" splitindex="true" windowtitle="${Name} API" doctitle="${Name}">
    <classpath refid="classpath" />
   </javadoc>
</target>
<!-- =================================================================== -->
<!-- 清除临时文件-->
<!-- =================================================================== -->
<target name="clean" depends="init">
   <delete dir="${build.src}"/>
   <delete dir="${build.dest}/org"/>
   <delete dir="${build.dest}/com"/>
   <delete dir="${buildwar.dest}"/>
   <delete>
    <fileset dir="${build.dest}" includes="**/*.class"/>
   </delete>
</target>


 

 

 

------------------------------------------------------------------------------------------------------------------------

 

 

 <?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="war" name="bid">
 <property name="app-name" value="bid" />
 <property name="release-version" value="20060720-1549" />
 <property name="src" value="src" />
 <property name="dist" value="dist" />
 <property name="classes" value="WebRoot/WEB-INF/classes" />
 <property name="lib" value="WebRoot/WEB-INF/lib" />
 <property name="ext-lib" value="ext-lib" />
 <property name="charset" value="UTF-8" />
 <property name="javadoc-packagenames" value="com.safemore.bid,com.safemore.bid.bid,com.safemore.bid.common,com.safemore.bid.issue,com.safemore.bid.logon,com.safemore.bid.util" />

 <patternset id="resources">
  <include name="**/*.jpe" />
  <include name="**/*.jpeg" />
  <include name="**/*.rmf" />
  <include name="**/*.wav" />
  <include name="**/*.midi" />
  <include name="**/*.mid" />
  <include name="**/*.au" />
  <include name="**/*.gif" />
  <include name="**/*.png" />
  <include name="**/*.jpg" />
  <include name="**/*.aiff" />
  <include name="**/*.properties" />
  <include name="**/*.txt" />
  <include name="**/*.xml" />
 </patternset>

 <path id="classpath">
  <pathelement location="${dist}" />
  <fileset dir="${lib}">
   <include name="*.jar" />
  </fileset>
  <fileset dir="${ext-lib}">
   <include name="*.jar" />
  </fileset>
 </path>

 <target name="init">
  <mkdir dir="${dist}" />
  <mkdir dir="${classes}" />
 </target>

 <target name="war" depends="resource, jar">
  <!--touch file="WEB-INF/web.xml"/-->
  <war compress="false" destfile="${dist}/${app-name}-${release-version}.war" webxml="WebRoot/WEB-INF/web.xml">
   <fileset dir="WebRoot">
    <include name="**/*.*" />
    <exclude name="WEB-INF/" />
   </fileset>
   <fileset dir="WebRoot">
    <include name="WEB-INF/*.*" />
    <exclude name="WEB-INF/web.xml" />
    <exclude name="WEB-INF/${app-name}.xml" />
    <exclude name="lib/" />
   </fileset>
   <lib dir="${lib}">
    <include name="*.jar" />
   </lib>
   <!--
   <lib dir="${dist}">
    <include name="*.jar" />
   </lib>
   -->
   <classes dir="${classes}" />
  </war>
 </target>

 <target name="resource">
  <copy todir="${classes}">
   <fileset dir="${src}">
    <patternset refid="resources" />
   </fileset>
  </copy>
 </target>

 <target name="clean">
  <delete dir="${classes}" />
  <delete dir="${dist}" />
 </target>

 <target name="compile" depends="init">
  <javac classpathref="classpath" debug="true" deprecation="false" destdir="${classes}" nowarn="false" encoding="${charset}">
   <src path="${src}" />
  </javac>
 </target>

 <target name="jar" depends="resource, compile, init">
  <jar compress="false" destfile="${dist}/${app-name}-${release-version}.jar">
   <fileset dir="${classes}">
    <include name="**/*.class" />
    <patternset refid="resources" />
   </fileset>
  </jar>
 </target>

 <target name="rejar" depends="clean, jar" />

 <target name="ear" depends="war">
  <ear destfile="${dist}/${app-name}-${release-version}.ear" appxml="META-INF/application-j1.3.xml">
   <fileset dir="${dist}" includes="${app-name}-${release-version}.war" />
  </ear>
 </target>

 <target name="release" depends="war">
  <zip destfile="${dist}/${app-name}-${release-version}.zip">
   <zipfileset dir="${dist}" includes="${app-name}-${release-version}.war" prefix="." />
   <zipfileset dir="db" includes="*.*" prefix="db" />
   <zipfileset dir="doc" includes="*.*" prefix="doc" />
  </zip>
 </target>

 <target name="javadoc">
  <javadoc encoding="${charset}" charset="${charset}" access="public" author="true" destdir="${dist}/javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.5" splitindex="true" use="true" version="true" packagenames="${javadoc-packagenames}" sourcepath="${src}" classpathref="classpath" />
 </target>
</project>

你可能感兴趣的:(tomcat,Web,xml,ant,ext)