`

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

    博客分类:
  • Ant
阅读更多
<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>


</project>
分享到:
评论
2 楼 cn-done 2009-06-29  
路过……学习,带走!
1 楼 crazyKangJava 2009-03-04  
 

相关推荐

    ant build.xml 配置文件

    我的开发环境是Eclipse,ant.xml是放在项目下的ant(新建),也可以修改project的basedir.

    ant build.xml

    经过几天学习,总结出ant build.xml的基本版,实现了: &lt;!--初始化操作--&gt; &lt;!--拷贝操作--&gt; &lt;!--编译--&gt; &lt;!--war打包--&gt; 执行顺序为: &lt;!--project的default属性为build,所以本target...

    build.xml构建文件

    ant的构建文件。打成war包,并且自动部署到tomcat上,只需要重新启动Tomcat项目就已经发布运行了。可以用ant命令执行此文件,也可以用eclipse执行。

    将项目打成war包

    特别简单 只需照着文档操作,就可实现。...再使用ant执行build.xml时必须在java的jre下的lib下的ext安装路径 把servlet-api.jar拷贝进去。 重新使用build.xml 命令打包即可.不然会出现javax.servlet.http 编译问题

    将项目打成jar包

    操作及其简单, ant是对项目编译,打包,...再使用ant执行build.xml时必须在java的jre下的lib下的ext安装路径 把servlet-api.jar拷贝进去。 重新使用build.xml 命令打包即可.不然会出现javax.servlet.http 编译问题

    使用Ant技术打包

    使用Ant技术对java项目进行打包,打成war包用来部署到web服务器

    apache-ant-1.9.3-src.tar

    每个ant脚本(缺省叫build.xml)中设置了一系列任务(target):比如对于一个一般的项目可能需要有以下任务。 * 任务1:usage 打印本脚本的帮助信息(缺省) * 任务2:clean 清空初始化环境 * 任务3:javadoc &lt;-- ...

    ant介绍Ant是什么

    1. Ant是什么?2. 安装Ant3. 运行Ant4. 编写build.xml5. 内置task(internet)6. EAR task(internet)7. WAR task(internet)8. JUnit task(internet)

    gwt_ant_build脚本研习

    gwt_ant_build脚本研习 目录 build.xml源文件 构建工程war的分析 自定义的build工程文件

    ant1.9资源

    若文件名为hello.xml时,读者还需要对命令做少许改变,改为:ant –f hello.xml sayHelloWorld、ant –buildfile hello.xml sayHelloWorld或ant –file hello.xml sayHelloWorld。 接下来开始向读者讲解本节的重点...

    Maven权威指南 很精典的学习教程,比ANT更好用

    WAR 10.2.6. EAR 10.2.7. 其它打包类型 10.3. 通用生命周期目标 10.3.1. Process Resources 10.3.2. Compile 10.3.3. Process Test Resources 10.3.4. Test Compile 10.3.5. Test 10.3.6. Install ...

    helloworld_war_ant:带有构建的Ant示例

    Helloworld战争Java WAR项目/模板项目的示例包含: Helloworld Servlet(使用注释) 静态html文件示例最基本的web.xml 编译时servlet-api.jar(因此不需要Java EE) 用于构建WAR的Ant build.xml 使用slf4j-api和sl4j...

    jocky 混肴编译rar包(ant和插件俩个版本)

    事实上,在Eclipse中使用Jocky时,Jocky也是首先针对所选工程生成Ant的Build文件(默认名称jocky_build.xml),然后再通过Ant完成混淆编译。 以下是Jocky在Eclipse中自动生成的Ant Build 文件示例: 1 ...

    Ant介绍以及基本使用指南

    Ant介绍以及基本使用指南,jar,war打包语法,打包的注意事项,及bulid.xml的做成。

    spring-boot-reference.pdf

    15.2. Importing XML Configuration 16. Auto-configuration 16.1. Gradually Replacing Auto-configuration 16.2. Disabling Specific Auto-configuration Classes 17. Spring Beans and Dependency Injection 18. ...

    Servlets和JSP核心技术 卷2(英文版) 第一部分

    Using Ant to Build a Web Application Section A.7. Example: Building a Web Application Section A.8. Using Ant to Create a WAR File Section A.9. Example: Creating a Web Application WAR File Index

    Servlets和JSP核心技术 卷2(英文版) 第二部分

    Using Ant to Build a Web Application Section A.7. Example: Building a Web Application Section A.8. Using Ant to Create a WAR File Section A.9. Example: Creating a Web Application WAR File Index

    Maven入门--概念与实例

    POM:POM(pom.xml)是Maven的核心文件,它是指示Maven如何工作的元数据文件,类似于Ant中的build.xml文件。POM文件位于每个工程的根目录中。 GroupId:groupId是一个工程的在全局中唯一的标识符,一般地,它就是...

    Ajax基础教程源码

    also contains a build.xml file from which the WAR file can be built using Ant. Use the dist target to compile the sources and build the WAR file: &gt; ant dist Each chapter WAR file has an index file ...

Global site tag (gtag.js) - Google Analytics