Antの罠

前のプロジェクトから「RedhatをES3に移行したらビルドが通らなくなった」との相談が来た。
どうもjspcあたりで処理が進まなくなるとのこと。


どうやら、使われているAntがプレインストールされていたver1.5系のrpm版Antらしい。
それが怪しかったので、最新の通常版のver1.6.5を展開して試してもらうと、次はこれが発生。

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher

なぬっ?環境変数ANT_HOMEもJAVA_HOMEも定義されてるし、
呼ばれてるantスクリプトも正しい場所のものだし。


で、しょうがないから行ってみてごにょごにょ確認して、
もげもげ調べてみたら、ありましたよ、こんなのが。

How do you get ant-1.6.x (or any version later than 1.5.2) to work on on RedHat ES 3?

Redhat ES 3.0 comes installed with ant 1.5.2. Even if you have your PATH and ANT_HOME variables set correctly to a later version of ant, you will always be forced to use the preinstalled version. To use a later version of ant on this OS you could do the following:

$ ant -version
Apache Ant version 1.5.2-23 compiled on November 12 2003
$ su -
# rpm -e ant ant-libs
# exit
$ hash -r
$ ant -version
Apache Ant version 1.6.2 compiled on July 16 2004

そしてこっちも若干関係があるのかな。

I installed Ant 1.6.x and now get java.lang.InstantiationException: org.apache.tools.ant.Main

The cause of this is that there is an old version of ant somewhere in the class path or configuration. A version of this problem may be seen on some linux systems. Some linux systems (Fedora Core 2 for example), comes with a version of ant pre-installed. There is a configuration file called /etc/ant.conf which if present, the ant shell script will 'dot' include. On Fedora Core 2, the /etc/ant.conf file resets the ANT_HOME environment variable to /usr/share/ant. This causes the problem that an old version of ant (1.5.x in this cause) will be used with a new version of the ant script file. One can check if this is the case by doing ant --noconfig -version.

つまりrpm版がインストールされていると、/etc/ant.confを見に行っちゃってて、それの影響でNoClassDefFoundErrorになっちゃってたんですね。
ふげーー。こんなもん気づかんよ。


ant を--noconfigオプション付きで実行すると、ANT_HOMEを使ってくれてうまく動いた。
罠だ、絶対。