Skip to content

Instantly share code, notes, and snippets.

@liangzai-cool
Created January 4, 2017 08:03
Show Gist options
  • Save liangzai-cool/813216346a741655b17a2c9ccc6c0bce to your computer and use it in GitHub Desktop.
Save liangzai-cool/813216346a741655b17a2c9ccc6c0bce to your computer and use it in GitHub Desktop.
blog's ant build file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="project-builder" basedir="." default="build-all">
<property environment="env"/>
<property name="debug" value="false"/>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="dist.dir" value="dist"/>
<property name="dist.war" value="blog.war"/>
<property name="jetty.home" value="${env.JETTY_HOME}"/>
<property name="webfiles.dir" value="WebContent"/>
<property name="classes.dir" value="${webfiles.dir}/WEB-INF/classes"/>
<property name="deploy.dir" value="${jetty.home}/webapps"/>
<property name="jdbc.url.prefix" value="jdbc:mysql://127.0.0.1:3306/"/>
<property name="jdbc.url.suffix" value="?characterEncoding=UTF-8"/>
<!-- 测试环境数据库配置 -->
<property name="jdbc.database.dev" value=""/>
<property name="jdbc.username.dev" value=""/>
<property name="jdbc.password.dev" value=""/>
<property name="jdbc.database" value=""/>
<property name="jdbc.username" value=""/>
<property name="jdbc.password" value=""/>
<property name="enable.task.init" value="true"/>
<property name="enable.task.complie" value="true"/>
<property name="enable.task.war" value="true"/>
<property name="enable.task.deploy" value="true"/>
<target name="build-all">
<echo>build begin...</echo>
<antcall target="build-init"/>
<antcall target="build-complie"/>
<antcall target="build-debug-env"/>
<antcall target="build-undebug-env"/>
<antcall target="build-war"/>
<antcall target="build-deploy"/>
<echo>build end.</echo>
</target>
<target name="build-init" if="${enable.task.init}">
<echo>init...</echo>
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
<condition property="debug">
<equals arg1="${debug}" arg2="true"/>
</condition>
<echo>is debug: ${debug}</echo>
</target>
<target name="build-complie" if="${enable.task.complie}">
<echo>complie...</echo>
<javac includeantruntime="false" srcdir="${src.dir}" debug="true" destdir="${build.dir}" encoding="UTF-8" source="1.7" target="1.7">
<classpath>
<fileset dir="WebContent/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${jetty.home}/lib">
<include name="servlet-api-3.1.jar"/>
</fileset>
</classpath>
</javac>
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="**/*"/>
</fileset>
</copy>
</target>
<target name="build-debug-env" if="${debug}">
<echo>debug env...</echo>
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.url=(.*)" replace="jdbc.url=${jdbc.url.prefix}${jdbc.database.dev}${jdbc.url.suffix}" />
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.username=(.*)" replace="jdbc.username=${jdbc.username.dev}" />
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.password=(.*)" replace="jdbc.password=${jdbc.password.dev}" />
</target>
<target name="build-undebug-env" unless="${debug}">
<echo>undebug env...</echo>
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.url=(.*)" replace="jdbc.url=${jdbc.url.prefix}${jdbc.database}${jdbc.url.suffix}" />
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.username=(.*)" replace="jdbc.username=${jdbc.username}" />
<replaceregexp file="${build.dir}/jdbc.properties" byline="true" encoding="utf-8" match="jdbc.password=(.*)" replace="jdbc.password=${jdbc.password}" />
</target>
<target name="build-war" if="${enable.task.war}">
<echo>war...</echo>
<war destfile="${dist.dir}/${dist.war}" encoding="UTF-8" webxml="${webfiles.dir}/WEB-INF/web.xml">
<lib dir="${webfiles.dir}/WEB-INF/lib"/>
<classes dir="${build.dir}"/>
<fileset dir="${webfiles.dir}">
<exclude name="**/*.class"/>
<exclude name="**/*.jar"/>
<exclude name="WEB-INF/web.xml"/>
</fileset>
</war>
</target>
<target name="build-deploy" if="${enable.task.deploy}">
<echo>deploy...</echo>
<copy file="${dist.dir}/${dist.war}" todir="${deploy.dir}"></copy>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment