浏览 3734 次
锁定老帖子 主题:如何使用ant的bulid.xml
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-04-25
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包,供大家下载使用。。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-04-25
大哥,用来格式化一下代码吧,密密麻麻的,看得头晕。
|
|
返回顶楼 | |
发表时间: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> |
|
返回顶楼 | |
发表时间:2007-04-25
,怎么使用呀,偶不会呀,请指教!!!!
|
|
返回顶楼 | |