Skip to content

Instantly share code, notes, and snippets.

@froop
Created November 19, 2011 05:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save froop/1378492 to your computer and use it in GitHub Desktop.
Save froop/1378492 to your computer and use it in GitHub Desktop.
[Java] Antで.warファイルを作成するサンプル
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<project basedir=".." default="build" name="sample">
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<target depends="clean,build-war" name="build"/>
<!-- 古いファイルを削除 -->
<target name="clean">
<delete dir="war/build"/>
<delete file="war/${ant.project.name}.war"/>
</target>
<!-- 作業ディレクトリ初期化 -->
<target name="init">
<mkdir dir="war/build/classes"/>
<copy includeemptydirs="false" todir="war/build/classes">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="war/build/classes">
<fileset dir="prop">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<!-- Javaコンパイル -->
<target depends="init" name="build-project">
<javac debug="true" debuglevel="${debuglevel}"
destdir="war/build/classes"
source="${source}" target="${target}">
<src path="src"/>
<classpath>
<pathelement location="war/build/classes"/>
<fileset dir="war/lib"/>
<fileset dir="WebContent/WEB-INF/lib"/>
</classpath>
</javac>
</target>
<!-- .warファイル作成 -->
<target depends="build-project" name="build-war">
<war destfile="war/${ant.project.name}.war"
webxml="WebContent/WEB-INF/web.xml">
<fileset dir="WebContent">
<include name="**/*" />
</fileset>
<classes dir="build/classes" />
</war>
</target>
</project>
@froop
Copy link
Author

froop commented Nov 20, 2011

以下のようなディレクトリ構成が前提(Eclipse標準の Dynamic Web Project で生成した雛形がベース)
src

  • (.javaファイル)
    prop
  • (.propertiesファイル)
    lib
  • servlet-api.jar
  • (コンパイルのみで必要なライブラリ)
    test
  • (JUnitの.javaファイル)
    WebContent
  • (JSP, HTML, js, cssなど)
  • META-INF
  • - context.xml
  • WEB-INF
  • - lib
  • - - (実行時に必要なライブラリ)
  • - web.xml
    dest
  • (生成したwarファイルの出力先)
    build.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment