25.4. GWT と Ant ターゲット
GWT アプリケーションをデプロイするためには JavaScript に対してもコンパイルを行う必要があります。これによりコードを圧縮し、難読化します。コマンドラインの代わりに Ant ユーティリティや GWT で提供される GUI ユーティリティを使うことができます。 これらを使うためには Ant クラスパスに Ant タスクの
JAR とダウンロードした GWTが必要です。
次を Ant ファイルの冒頭付近に配置します。
<taskdef uri="antlib:de.samaflost.gwttasks"
resource="de/samaflost/gwttasks/antlib.xml"
classpath="./lib/gwttasks.jar"/>
<property file="build.properties"/>
以下を含む
build.properties ファイルを作成します。
gwt.home=/gwt_home_dir
GWT がインストールされたディレクトリを指していなければなりません。 次にターゲットを作成します。
<!-- the following are are handy utilities for doing GWT development.
To use GWT, you will of course need to download GWT seperately -->
<target name="gwt-compile">
<!-- in this case, we are "re homing" the gwt generated stuff, so
in this case we can only have one GWT module - we are doing this
deliberately to keep the URL short -->
<delete>
<fileset dir="view"/>
</delete>
<gwt:compile outDir="build/gwt"
gwtHome="${gwt.home}"
classBase="${gwt.module.name}"
sourceclasspath="src"/>
<copy todir="view">
<fileset dir="build/gwt/${gwt.module.name}"/>
</copy>
</target>
呼び出されると、 このターゲットは GWT アプリケーションをコンパイルしてそれを指定ディレクトリにコピーします (WAR の
webapp セクションの場合が多い)。
注記
gwt-compile で生成されたコードは絶対に編集しないでください。 編集が必要な場合には GWT ソースディレクトリ内で行ってください。
GWT でアプリケーション開発を行う予定の場合は、GWT に含まれているホストモードブラウザの使用を強く推奨します。