`
liyanboss
  • 浏览: 142581 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

如何使用ant的bulid.xml

阅读更多
最近电脑系统有些问题,硬盘全部被格式化,原来的所有文件都没有了,最近想研究一下struts2,但是要用ant来继承部署webapp,却忘了如何来配置,只好重新查资料编写,现在把它记载下来,方便以后使用。

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloStruts2" basedir="." default="">
	<property name="webapp.name" value="myweb" />
	<property name="webapp.src.dir" value="src" />
	<property name="webapp.lib.dir" value="lib" />
	<property name="webapp.web.dir" value="WebRoot" />
	<property name="webapp.test.dir" value="test" />
	<property name="webapp.config.dir" value="config" />
	<property name="build.dir" value="build" />
	<property name="build.dist.dir" value="${build.dir}/dist" />
	<property name="build.dist.web.dir" value="${build.dist.dir}/web" />
	<property name="build.dist.lib.dir" value="${build.dist.dir}/lib" />
	<property name="build.dist.config.dir" value="${build.dist.dir}/config" />
	<property name="build.dist.classes.dir" value="${build.dist.dir}/classes" />

	<property name="app.host" value="localhost" />
	<property name="app.port" value="8080" />
	<property name="tomcat.home" value="../apache-tomcat-6.0.10" />
	<property name="tomcat.manager.url" value="http://${app.host}:${app.port}/manager" />
	<property name="tomcat.manager.username" value="admin" />
	<property name="tomcat.manager.password" value="" />

	<path id="master-classpath">
		<fileset dir="${webapp.lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<pathelement path="${build.dist.classes.dir}" />
	</path>
	<path id="tomcat-classpath">
		<fileset file="${tomcat.home}/lib/*.jar" />
	</path>

	<target name="-clean.build.dist.dir">
		<delete dir="${build.dist.dir}" />
	</target>
	<target name="-clean.tomcat.work.and.logs">
		<delete dir="${tomcat.home}/logs" />
		<delete dir="${tomcat.home}/work" />
	</target>
	<target name="-clean.webapp.in.tomcat.webapps">
		<delete dir="${tomcat.home}/webapps/${webapp.name}" />
		<delete file="${tomcat.home}/webapps/${webapp.name}.war" />
	</target>
	<target name="-make.build.dist.dir">
		<mkdir dir="${build.dist.web.dir}" />
		<mkdir dir="${build.dist.lib.dir}" />
		<mkdir dir="${build.dist.config.dir}" />
		<mkdir dir="${build.dist.classes.dir}" />
	</target>
	<target name="-clean.build.and.init" depends="-clean.build.dist.dir, -make.build.dist.dir" />
	<target name="-clean.tomcat.webapps" depends="-clean.tomcat.work.and.logs, -clean.webapp.in.tomcat.webapps" />

	<target name="-compile.classes">
		<javac srcdir="${webapp.src.dir}" destdir="${build.dist.classes.dir}" encoding="UTF-8" source="1.6" fork="true">
			<classpath refid="master-classpath" />
			<compilerarg value="-Xlint:unchecked" />
		</javac>
	</target>

	<target name="-compile.config">
		<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/common" includes="*.native" ext=".properties" />
		<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/spring" includes="*.native" ext=".properties" />
		<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/struts2" includes="*.native" ext=".properties" />
		<copy todir="${build.dist.config.dir}" overwrite="true">
			<fileset dir="${webapp.config.dir}/common">
				<exclude name="*.native" />
				<include name="*.properties" />
				<include name="*.xml" />
			</fileset>
			<fileset dir="${webapp.config.dir}/spring">
				<exclude name="*.native" />
				<include name="*.properties" />
				<include name="*.xml" />
			</fileset>
			<fileset dir="${webapp.config.dir}/struts2">
				<exclude name="*.native" />
				<include name="*.properties" />
				<include name="*.xml" />
			</fileset>
			<fileset dir="${webapp.src.dir}">
				<include name="**/*.xml" />
			</fileset>
		</copy>
	</target>
	<target name="-compile" depends="-compile.classes, -compile.config" />

	<target name="-build.webapp.war">
		<copy todir="${build.dist.lib.dir}" overwrite="true">
			<fileset dir="${webapp.lib.dir}/struts2" />
		</copy>
		<copy todir="${build.dist.web.dir}" overwrite="true">
			<fileset dir="${webapp.web.dir}" />
		</copy>
		<copy todir="${build.dist.classes.dir}" overwrite="true">
			<fileset dir="${build.dist.config.dir}" />
		</copy>
		<war destfile="${build.dist.dir}/${webapp.name}.war" webxml="${build.dist.web.dir}/WEB-INF/web.xml">
			<fileset dir="${build.dist.web.dir}" />
			<lib dir="${build.dist.lib.dir}" />
			<classes dir="${build.dist.classes.dir}" />
		</war>
	</target>

	<target name="copy.war.to.tomcat" depends="-clean.build.and.init, -compile, -clean.webapp.in.tomcat.webapps, -build.webapp.war" description="copy to tomcat">
		<copy todir="${tomcat.home}/webapps" overwrite="true">
			<fileset file="${build.dist.dir}/${webapp.name}.war" />
		</copy>
	</target>

	<taskdef name="webapp.deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat-classpath" />
	<taskdef name="webapp.undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat-classpath" />
	<target name="-webapp.install">
		<webapp.deploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${webapp.name}" war="${build.dist.dir}/${webapp.name}.war" />
	</target>

	<target name="webapp.reinstall" depends="stop.tomcat, -clean.build.and.init, -compile, -clean.tomcat.webapps, start.tomcat, -build.webapp.war, -webapp.install" description="webapp reinstall" />



	<!-- ============================================================== -->
	<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
	<!-- ============================================================== -->

	<!-- start tomcat with bootstrap.jar-->
	<property name="catalina.java.home" value="${java.home}" />
	<property name="catalina.home" value="${tomcat.home}" />
	<property name="catalina.base" value="${catalina.home}" />
	<property name="catalina.tmpdir" value="${catalina.base}/temp" />
	<property name="jpda.address" value="8000" />

	<path id="java.classpath">
		<pathelement location="${catalina.java.home}/../lib/tools.jar" />
	</path>
	<path id="catalina.classpath">
		<pathelement location="${catalina.home}/bin/bootstrap.jar" />
		<pathelement location="${catalina.home}/bin/commons-logging-api.jar" />
	</path>

	<target name="start.tomcat" description="start tomcat by bootstrap.jar">
		<echo message="Starting Tomcat server" />
		<echo message="Using CATALINA_BASE: ${catalina.base}" />
		<echo message="Using CATALINA_HOME: ${catalina.home}" />
		<java classname="org.apache.catalina.startup.Bootstrap" spawn="yes" fork="true">
			<jvmarg value="-Dcatalina.home=${catalina.home}" />
			<classpath>
				<path refid="java.classpath" />
				<path refid="catalina.classpath" />
			</classpath>
			<arg value="start" />
		</java>
	</target>

	<target name="start.tomcat.debug" description="start tomcat by bootstrap.jar">
		<echo message="Starting Tomcat server" />
		<echo message="Using CATALINA_BASE: ${catalina.base}" />
		<echo message="Using CATALINA_HOME: ${catalina.home}" />
		<java classname="org.apache.catalina.startup.Bootstrap" spawn="no" fork="true">
			<jvmarg value="-Dcatalina.home=${catalina.home}" />
			<jvmarg value="-Xdebug" />
			<jvmarg value="-Xnoagent" />
			<jvmarg value="-Djava.compiler=none" />
			<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${jpda.address}" />
			<classpath>
				<path refid="java.classpath" />
				<path refid="catalina.classpath" />
			</classpath>
		</java>
	</target>

	<target name="stop.tomcat" description="stop tomcat by bootstrap.jar">
		<echo message="Stopping Tomcat server" />
		<echo message="Using CATALINA_BASE: ${catalina.base}" />
		<echo message="Using CATALINA_HOME: ${catalina.home}" />
		<java classname="org.apache.catalina.startup.Bootstrap" spawn="yes" fork="true" failonerror="false">
			<classpath>
				<path refid="java.classpath" />
				<path refid="catalina.classpath" />
			</classpath>
			<jvmarg value="-Dcatalina.home=${catalina.home}" />
			<arg value="stop" />
		</java>
	</target>
</project>
           
   
同时上传一个blank的war包,供大家下载使用。。
分享到:
评论
3 楼 liyanboss 2007-04-25  
怎么使用呀,偶不会呀,请指教!!!!
2 楼 liyanboss 2007-04-25  
怎么发的bulid.xml格式不对,重发一个。
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloStruts2" basedir="." default="">
<property name="webapp.name" value="myweb" />
<property name="webapp.src.dir" value="src" />
<property name="webapp.lib.dir" value="lib" />
<property name="webapp.web.dir" value="WebRoot" />
<property name="webapp.test.dir" value="test" />
<property name="webapp.config.dir" value="config" />
<property name="build.dir" value="build" />
<property name="build.dist.dir" value="${build.dir}/dist" />
<property name="build.dist.web.dir" value="${build.dist.dir}/web" />
<property name="build.dist.lib.dir" value="${build.dist.dir}/lib" />
<property name="build.dist.config.dir" value="${build.dist.dir}/config" />
<property name="build.dist.classes.dir" value="${build.dist.dir}/classes" />

<property name="app.host" value="localhost" />
<property name="app.port" value="8080" />
<property name="tomcat.home" value="../apache-tomcat-6.0.10" />
<property name="tomcat.manager.url" value="http://${app.host}:${app.port}/manager" />
<property name="tomcat.manager.username" value="admin" />
<property name="tomcat.manager.password" value="" />

<path id="master-classpath">
<fileset dir="${webapp.lib.dir}">
<include name="**/*.jar" />
</fileset>
<pathelement path="${build.dist.classes.dir}" />
</path>
<path id="tomcat-classpath">
<fileset file="${tomcat.home}/lib/*.jar" />
</path>

<target name="-clean.build.dist.dir">
<delete dir="${build.dist.dir}" />
</target>
<target name="-clean.tomcat.work.and.logs">
<delete dir="${tomcat.home}/logs" />
<delete dir="${tomcat.home}/work" />
</target>
<target name="-clean.webapp.in.tomcat.webapps">
<delete dir="${tomcat.home}/webapps/${webapp.name}" />
<delete file="${tomcat.home}/webapps/${webapp.name}.war" />
</target>
<target name="-make.build.dist.dir">
<mkdir dir="${build.dist.web.dir}" />
<mkdir dir="${build.dist.lib.dir}" />
<mkdir dir="${build.dist.config.dir}" />
<mkdir dir="${build.dist.classes.dir}" />
</target>
<target name="-clean.build.and.init" depends="-clean.build.dist.dir, -make.build.dist.dir" />
<target name="-clean.tomcat.webapps" depends="-clean.tomcat.work.and.logs, -clean.webapp.in.tomcat.webapps" />

<target name="-compile.classes">
<javac srcdir="${webapp.src.dir}" destdir="${build.dist.classes.dir}" encoding="UTF-8" source="1.6" fork="true">
<classpath refid="master-classpath" />
<compilerarg value="-Xlint:unchecked" />
</javac>
</target>

<target name="-compile.config">
<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/common" includes="*.native" ext=".properties" />
<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/spring" includes="*.native" ext=".properties" />
<native2ascii encoding="UTF-8" dest="${build.dist.config.dir}" src="${webapp.config.dir}/struts2" includes="*.native" ext=".properties" />
<copy todir="${build.dist.config.dir}" overwrite="true">
<fileset dir="${webapp.config.dir}/common">
<exclude name="*.native" />
<include name="*.properties" />
<include name="*.xml" />
</fileset>
<fileset dir="${webapp.config.dir}/spring">
<exclude name="*.native" />
<include name="*.properties" />
<include name="*.xml" />
</fileset>
<fileset dir="${webapp.config.dir}/struts2">
<exclude name="*.native" />
<include name="*.properties" />
<include name="*.xml" />
</fileset>
<fileset dir="${webapp.src.dir}">
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="-compile" depends="-compile.classes, -compile.config" />

<target name="-build.webapp.war">
<copy todir="${build.dist.lib.dir}" overwrite="true">
<fileset dir="${webapp.lib.dir}/struts2" />
</copy>
<copy todir="${build.dist.web.dir}" overwrite="true">
<fileset dir="${webapp.web.dir}" />
</copy>
<copy todir="${build.dist.classes.dir}" overwrite="true">
<fileset dir="${build.dist.config.dir}" />
</copy>
<war destfile="${build.dist.dir}/${webapp.name}.war" webxml="${build.dist.web.dir}/WEB-INF/web.xml">
<fileset dir="${build.dist.web.dir}" />
<lib dir="${build.dist.lib.dir}" />
<classes dir="${build.dist.classes.dir}" />
</war>
</target>

<target name="copy.war.to.tomcat" depends="-clean.build.and.init, -compile, -clean.webapp.in.tomcat.webapps, -build.webapp.war" description="copy to tomcat">
<copy todir="${tomcat.home}/webapps" overwrite="true">
<fileset file="${build.dist.dir}/${webapp.name}.war" />
</copy>
</target>

<taskdef name="webapp.deploy" classname="org.apache.catalina.ant.DeployTask" classpathref="tomcat-classpath" />
<taskdef name="webapp.undeploy" classname="org.apache.catalina.ant.UndeployTask" classpathref="tomcat-classpath" />
<target name="-webapp.install">
<webapp.deploy url="${tomcat.manager.url}" username="${tomcat.manager.username}" password="${tomcat.manager.password}" path="/${webapp.name}" war="${build.dist.dir}/${webapp.name}.war" />
</target>

<target name="webapp.reinstall" depends="stop.tomcat, -clean.build.and.init, -compile, -clean.tomcat.webapps, start.tomcat, -build.webapp.war, -webapp.install" description="webapp reinstall" />



<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->

<!-- start tomcat with bootstrap.jar-->
<property name="catalina.java.home" value="${java.home}" />
<property name="catalina.home" value="${tomcat.home}" />
<property name="catalina.base" value="${catalina.home}" />
<property name="catalina.tmpdir" value="${catalina.base}/temp" />
<property name="jpda.address" value="8000" />

<path id="java.classpath">
<pathelement location="${catalina.java.home}/../lib/tools.jar" />
</path>
<path id="catalina.classpath">
<pathelement location="${catalina.home}/bin/bootstrap.jar" />
<pathelement location="${catalina.home}/bin/commons-logging-api.jar" />
</path>

<target name="start.tomcat" description="start tomcat by bootstrap.jar">
<echo message="Starting Tomcat server" />
<echo message="Using CATALINA_BASE: ${catalina.base}" />
<echo message="Using CATALINA_HOME: ${catalina.home}" />
<java classname="org.apache.catalina.startup.Bootstrap" spawn="yes" fork="true">
<jvmarg value="-Dcatalina.home=${catalina.home}" />
<classpath>
<path refid="java.classpath" />
<path refid="catalina.classpath" />
</classpath>
<arg value="start" />
</java>
</target>

<target name="start.tomcat.debug" description="start tomcat by bootstrap.jar">
<echo message="Starting Tomcat server" />
<echo message="Using CATALINA_BASE: ${catalina.base}" />
<echo message="Using CATALINA_HOME: ${catalina.home}" />
<java classname="org.apache.catalina.startup.Bootstrap" spawn="no" fork="true">
<jvmarg value="-Dcatalina.home=${catalina.home}" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xnoagent" />
<jvmarg value="-Djava.compiler=none" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${jpda.address}" />
<classpath>
<path refid="java.classpath" />
<path refid="catalina.classpath" />
</classpath>
</java>
</target>

<target name="stop.tomcat" description="stop tomcat by bootstrap.jar">
<echo message="Stopping Tomcat server" />
<echo message="Using CATALINA_BASE: ${catalina.base}" />
<echo message="Using CATALINA_HOME: ${catalina.home}" />
<java classname="org.apache.catalina.startup.Bootstrap" spawn="yes" fork="true" failonerror="false">
<classpath>
<path refid="java.classpath" />
<path refid="catalina.classpath" />
</classpath>
<jvmarg value="-Dcatalina.home=${catalina.home}" />
<arg value="stop" />
</java>
</target>
</project>
1 楼 rainlife 2007-04-25  
大哥,用
来格式化一下代码吧,密密麻麻的,看得头晕。

相关推荐

    ant build.xml 详解

    Ant支持定义和使用属性,它们允许在`build.xml`中存储和复用值。例如,`&lt;property name="src.dir" value="src"/&gt;`定义了一个名为`src.dir`的属性,其值为`src`。 7. **文件集(Filesets)** 文件集允许你指定一组...

    ant build.xml 使用实例

    Apache Ant 是一个广泛使用的Java构建工具,它以XML格式定义构建脚本,即`build.xml`文件。这个文件包含了构建项目的整个流程,从编译源代码到生成最终的可执行或部署包。下面我们将深入探讨`build.xml`的使用以及...

    一个常用的ant的build.xml

    Ant是基于XML的,它的核心在于`build.xml`文件,这个文件是项目的构建脚本,详细定义了构建过程中的各种任务和依赖关系。 标题“一个常用的ant的build.xml”暗示了我们讨论的是一个标准且常见的Ant构建配置文件。...

    ant的build.xml模板

    《Ant的build.xml模板详解与应用》 在软件开发领域,构建工具是不可或缺的一部分,它帮助开发者自动化地完成编译、测试、打包等任务。Apache Ant作为Java领域的一款经典构建工具,以其灵活性和强大的功能深受广大...

    ant build.xml文件详解

    Ant 的构建文件是 XML 格式的文件,定义了构建过程,并被团队开发中每个人使用。构建文件默认命名为 build.xml,也可以取其他的名字。 Ant 构建文件的基本结构包括: 1. `&lt;project&gt;`标签:每个构建文件对应一个...

    ant build.xml编写

    《Ant build.xml构建详解》 在软件开发过程中,构建工具起着至关重要的作用,它能够自动化执行编译、测试、打包等任务。Apache Ant是Java领域广泛应用的一个构建工具,其核心在于一个名为`build.xml`的配置文件。...

    jmeter+ant 持续集成build.xml文件

    jmeter+ant 持续集成build.xml文件,直接使用ant命令执行jmeter脚本文件,得到图形测试报告

    ant build.xml 配置文件

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

    Jmeter+ant实现测试报告build.xml和报告模板jmeter-results-newreport.xsl

    3. **build.xml文件详解**:`build.xml`是Ant的构建文件,其中包含了一系列的任务和目标。例如,你可以定义一个目标来启动JMeter,另一个目标来生成测试报告,甚至还有一个目标用来发送测试结果的邮件通知。在描述中...

    ANT_发布项目中_build.xml_文件的详细配置

    本文将深入探讨在Ant发布项目中的`build.xml`文件配置,帮助开发者理解并掌握如何通过这个核心配置文件来自动化项目的编译、测试、打包和部署流程。 ### 一、`build.xml`文件结构解析 `build.xml`是Ant的核心配置...

    生成ANT所需要的Build,xml文件

    "生成ANT所需要的Build.xml文件"这一主题,核心在于如何通过Python程序自动生成ANT的配置文件——build.xml。 首先,我们要理解ANT的build.xml文件。它是ANT的核心,包含了一系列的构建目标和任务。这些目标定义了...

    ant build.xml例子

    这篇博客文章“ant build.xml例子”可能详细介绍了如何使用Ant来管理Java项目的构建过程。 `build.xml`文件是Ant的核心,它使用XML语法定义了一系列的任务(tasks),这些任务包含了构建过程中的各种操作,如编译源...

    ant 较完整的build.xml解释

    下面是一个简单的`build.xml`示例,展示了如何使用Ant构建一个简单的Java项目。 ```xml &lt;project name="MyApp" default="build" basedir="."&gt; &lt;property name="src.dir" value="src"/&gt; &lt;property name="build....

    ant +build.xml 文件Jenkins部署javaEE项目

    ant +build.xml 文件Jenkins部署javaEE项目,助力成功自动化部署。ant +build.xml 文件Jenkins部署javaEE项目,助力成功自动化部署。ant +build.xml 文件Jenkins部署javaEE项目,助力成功自动化部署。ant +build.xml...

    ant build.xml

    xdoclet 配置文件,可以自动建立hibernate配置文件和mapping文件

    ant打包ant的build.xml的详解

    Ant 打包 ant 的 build.xml 详解 Ant 是一个流行的自动化构建工具,广泛应用于软件开发和项目自动化构建中。本文将详细介绍 Ant 的环境变量配置和 build.xml 文件的配置详解。 第一步:安装 Apache Ant 在开始...

    ANT-build.xml命令详解

    **ANT-build.xml命令详解** Apache Ant 是一个Java平台上的开源构建工具,它通过XML格式的配置文件(如`build.xml`)来定义构建任务。Ant的设计理念是“简单就是美”,它使得Java项目的构建过程变得可配置且易于...

    ant 默认构建文件 demo build.xml

    ant build.xml demo 供自己及好友学习,能很快上手

    Ant_build.xml配置实例

    Ant_build.xml配置实例,Ant的详细配置,很实用

    ant打包配置文件build.xml

    ant打包配置文件,参考了博主的文章,作者:失语失芯不失梦 链接:https://www.jianshu.com/p/04cfce59890a 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Global site tag (gtag.js) - Google Analytics