Skip to content

Instantly share code, notes, and snippets.

@cuter44
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save cuter44/9203876 to your computer and use it in GitHub Desktop.

Select an option

Save cuter44/9203876 to your computer and use it in GitHub Desktop.
Java defaults
<?xml version="1.0" encoding="utf-8"?>
<!--
Default build.xml file for local Java Project
==========================================
@depend ant-1.9.2+ (tested, actually more below this)
@author "galin"<[email protected]>
@version 1.0.0 build 2014/2/25
==========================================
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="project-name" basedir="." default="build-all" >
<!-- 变量 -->
<property name="srcdir" value="src" />
<property name="dtlibdir" value="lib" />
<property name="javadocdir" value="javadoc" />
<property name="destdir" value="bin" />
<property name="version" value="0.0.1" />
<path id="classpath">
<!-- lib 存放开发及测试用库 -->
<fileset id="dt-packages" dir="${dtlibdir}">
<include name="*.jar" />
</fileset>
<pathelement path="${destdir}" />
</path>
<!-- 初始化目录树 -->
<target name="init" description="初始化目录树及默认配置文件, 注意会覆盖 web.xml">
<mkdir dir="${srcdir}" />
<mkdir dir="${dtlibdir}" />
<mkdir dir="${destdir}" />
</target>
<!-- 编译 -->
<target name="copy-config" description="复制配置文件">
<copy todir="${destdir}">
<fileset dir="${srcdir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
</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="jar" description="生成jar">
<antcall target="build-all"/>
<jar destfile="${ant.project.name}-${version}.jar" basedir="${destdir}" />
</target>
<!-- 生成javadoc -->
<target name="javadoc" description="生成javadoc">
<javadoc sourcepath="${srcdir}" destdir="${javadocdir}" private="true" classpathref="classpath"/>
</target>
<!-- 调试 -->
<target name="debug" description="本地测试, 使用-Ddebug.main=&lt;类名&gt;指定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=&lt;类名&gt;指定入口类">
<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