ここでどのシステム プロパティがどの値に設定されているかを確認したかったので、(ここで新しい Java プログラムを作成しない場合) 最も簡単な方法は、ant ビルド スクリプトに次の行を追加することです。
<target name="properties">
<echoproperties/>
</target>
しかし、ant を実行すると、次のエラー メッセージが表示されます。
/u/ebermann/projektoj/stackoverflow-examples/build.xml:19: Problem: failed to create task or type echoproperties
Cause: the class org.apache.tools.ant.taskdefs.optional.EchoProperties was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-/usr/share/ant/lib
-/u/ebermann/.ant/lib
-a directory added on the command line with the -lib argument
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
よし、パニックにはならないけど、どうしよう。
ここに Ant 1.7.1 (OpenSUSE システム) がありますが、残念ながらこのバージョンのドキュメントはありません。また、現在の Ant バージョンまたは古いバージョンのドキュメントをインストールするルートではありません (ダウンロードしたばかりで、まだインストールされています)。ここではどのjarファイルが必要かは言いません)。上記のディレクトリのうち、/usr/share/ant/lib
存在するのは だけですが、 optional
.
必要なjarファイルをダウンロードしてホームディレクトリに置きたいのですが、どこにありますか? Ant のダウンロード アーカイブにはそのようなものは何も含まれておらず、他にどこを検索すればよいかわかりません。(ちょっとググったけど、何も出てこなかった。
それで、誰かが正しいjarファイルを見つける場所を教えてもらえますか?
(解決策は非常に簡単で、何かが私の視界を遮っているだけだと思います。)
vahaptの回答の後、ファイルをapache リポジトリ/u/ebermann/.ant/lib
からダウンロードし、エラー メッセージに記載されているディレクトリに配置しました。再度実行ant properties
- 上記と同じ結果。
$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class'
org/apache/tools/ant/taskdefs/optional/EchoProperties.class
これはうまくいくように見えます - エラーメッセージは単に間違っていますか?
CLASSPATH に直接入れると、次のように動作します。
$ CLASSPATH=/u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar ant properties
Buildfile: build.xml
properties:
[echoproperties] #Ant properties
[echoproperties] #Thu Mar 10 00:46:22 CET 2011
...
[echoproperties] user.name=ebermann
[echoproperties] user.timezone=
BUILD SUCCESSFUL
Total time: 0 seconds
通常の CLASSPATH 変数を変更したくありません。このディレクトリに配置することで機能するはずですが、何か問題があることを理解しましたか?
何かアイデアはありますか、それともこれはアリのバグですか?
(また、このファイルが ant ドキュメントのどこにも記載されていないのはなぜですか?)
編集:
vahaptからの回答の後、私の ant ビルドファイルは次のようになります。
<project name="stackoverflow-examples" basedir=".">
<target name="echoproperties.prepare">
<available property="echoproperties.works"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
/>
</target>
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties">
<classpath>
<fileset dir="${user.home}/.ant/lib">
<include name="ant-nodeps.jar" />
</fileset>
</classpath>
</taskdef>
</target>
<target name="properties" depends="echoproperties.init">
<echoproperties/>
</target>
</project>
これにより、Ant クラスパスにタスクが存在しない場合にのみ、タスクが再登録されます。(したがって、このファイルがホーム ディレクトリにない完全な ant インストールでも機能するはずです)。
This is not a bug; it is a configuration problem
指定されたディレクトリにファイルを置くことは役に立たないので、それは完全に正しいとは言えません。
${user.home}/.ant/lib
もう 1 つの興味深い観察: (つまり、現在/u/ebermann/.ant/lib/ant-nodeps.jar
)の nodeps.jarは、既にクラス パス( で示されているもの)${java.class.path}
にありますが、<echoproperties>
このtaskdef
.
したがって、これも機能します。
<target name="echoproperties.init"
depends="echoproperties.prepare"
unless="echoproperties.works">
<taskdef name="echoproperties"
classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"
classpath="${java.class.path}" />
</target>