Last active
August 29, 2015 13:56
-
-
Save cuter44/8969130 to your computer and use it in GitHub Desktop.
JavaWeb defaults
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
Default build.xml file for JavaWeb Project | |
========================================== | |
@depend ant-1.9.2+ (tested, actually more below this) | |
@author "galin"<cuter44@qq.com> | |
@version 1.3.1 build 2014/2/15 | |
========================================== | |
You can do whatever to this file as you wish. | |
This file and other attachement is provided as-if, and no warranty. | |
========================================== | |
[USAGE] | |
Config your project-name right below, then paste it to your project-base. use 'ant -projecthelp' to view all commands. | |
--> | |
<project name="?" basedir="." default="build-all" > | |
<!-- 变量 --> | |
<property name="srcdir" value="src" /> | |
<property name="dtlibdir" value="lib" /> | |
<property name="webdir" value="web" /> | |
<property name="javadocdir" value="javadoc" /> | |
<property name="webinfdir" value="${webdir}/WEB-INF" /> | |
<property name="rtlibdir" value="${webinfdir}/lib" /> | |
<property name="destdir" value="${webinfdir}/classes" /> | |
<path id="classpath"> | |
<fileset id="rt-packages" dir="${rtlibdir}"> | |
<include name="*.jar" /> | |
</fileset> | |
<fileset id="dt-packages" dir="${dtlibdir}"> | |
<include name="*.jar" /> | |
</fileset> | |
<pathelement path="${destdir}" /> | |
</path> | |
<pathconvert property="webdir.absolute"> | |
<path location="${basedir}\${webdir}" /> | |
</pathconvert> | |
<!-- 初始化目录树 --> | |
<target name="init" description="初始化目录树及默认配置文件, 注意会覆盖 web.xml"> | |
<mkdir dir="${srcdir}" /> | |
<mkdir dir="${dtlibdir}" /> | |
<mkdir dir="${rtlibdir}" /> | |
<mkdir dir="${destdir}" /> | |
<antcall target="init-genwebxml" /> | |
<antcall target="init-gendeploy" /> | |
</target> | |
<target name="init-genwebxml" description="初始化默认的 web.xml"> | |
<echo file="${webinfdir}/web.xml"><?xml version="1.0" encoding="UTF-8"?> | |
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:web="http://java.sun.com/xml/ns/javaee" | |
xmlns="http://java.sun.com/xml/ns/javaee" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |
version="3.0"> | |
<display-name>${ant.project.name}</display-name> | |
<!-- | |
<servlet> | |
<servlet-name></servlet-name> | |
<servlet-class></servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name></servlet-name> | |
<url-pattern></url-pattern> | |
</servlet-mapping> | |
--> | |
<welcome-file-list> | |
<welcome-file>index.html</welcome-file> | |
<welcome-file>index.htm</welcome-file> | |
<welcome-file>index.jsp</welcome-file> | |
</welcome-file-list> | |
</web-app> | |
</echo> | |
</target> | |
<target name="init-gendeploy" description="生成指向配置文件, 用于 tomcat 的引用部署"> | |
<echo file="${ant.project.name}.xml"><!-- note: copy this file to your TOMCAT_HOME/conf/Catalina/localhost(or other as your actual) to deploy --> | |
<Context docBase="${webdir.absolute}"> | |
</Context> | |
</echo> | |
</target> | |
<!-- 编译 --> | |
<target name="build" description="编译"> | |
<mkdir dir="${destdir}" /> | |
<antcall target="copy-config" /> | |
<javac srcdir="${srcdir}" destdir="${destdir}" failonerror="true" debug="true" includeantruntime="false" encoding="utf-8"> | |
<compilerarg value="-Xlint:unchecked"/> | |
<classpath refid="classpath" /> | |
</javac> | |
</target> | |
<target name="clear-built" description="清理"> | |
<delete> | |
<fileset dir="${destdir}" includes="**/*"/> | |
</delete> | |
</target> | |
<target name="build-all" description="全部重新编译"> | |
<antcall target="clear-built" /> | |
<antcall target="build" /> | |
</target> | |
<target name="copy-config" description="复制配置文件"> | |
<copy todir="${destdir}"> | |
<fileset dir="${srcdir}"> | |
<include name="**/*.xml" /> | |
<include name="**/*.properties" /> | |
</fileset> | |
</copy> | |
</target> | |
<!-- 生成javadoc --> | |
<target name="javadoc" description="生成javadoc"> | |
<javadoc sourcepath="${srcdir}" destdir="${javadocdir}" private="true" classpathref="classpath" encoding="utf-8" /> | |
</target> | |
<!-- 生成war --> | |
<target name="war" description="生成war"> | |
<antcall target="build-all"/> | |
<jar destfile="${ant.project.name}.war" basedir="${webdir}" /> | |
</target> | |
<!-- 调试 --> | |
<target name="debug" description="本地测试, 使用-Ddebug.main=<类名>指定jvm的入口类"> | |
<java classname="${debug.main}" fork="true" dir="${destdir}"> | |
<!-- 启用断言 --> | |
<jvmarg value="-ea" /> | |
<!-- 启用调试 --> | |
<jvmarg value="-Xdebug"/> | |
<!-- 启用远程调试 --> | |
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8288,suspend=y,server=y"/> | |
<classpath refid="classpath" /> | |
</java> | |
</target> | |
<!-- 运行 --> | |
<target name="run" description="直接运行, 使用-Drun.main=<类名>指定入口类"> | |
<java classname="${run.main}" fork="true" dir="${destdir}"> | |
<classpath refid="classpath" /> | |
</java> | |
</target> | |
<!-- 工具集 --> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment