FaqIvyJa
プロジェクトで Maven リポジトリからライブラリの取得に Ivy を使えますか?
はい、使えます。ただ設定のためにいくつかのファイルを変更する必要があります。また GUI ではサポートしていません。次の例を試してみてください:
1. Ivy をダウンロード (1.3 RC2 以上、1.2 ではバグがあります):
http://www.jayasoft.org/ivy/download
2. Java アプリケーションプロジェクトを作成します
3. ivy.xml ファイルをプロジェクトのトップディレクトリに作成します:
<?xml version="1.0" encoding="UTF-8"?> <ivy-module version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "http://www.jayasoft.org/misc/ivy/samples/ivy.xsd"> <info organisation="myself" module="ivytest"/> <dependencies> <dependency org="apache" name="dom4j" rev="1.6"/> </dependencies> </ivy-module>
Alt-Shift-F9 で構文の確認ができます。
4. build.xml にいくつかのカスタムロジックを追加します:
<target name="-check-for-ivy"> <available property="have.ivy" resource="fr/jayasoft/ivy/ant/antlib.xml"/> </target> <target name="-ivy-define" depends="-check-for-ivy" unless="have.ivy"> <taskdef resource="fr/jayasoft/ivy/ant/antlib.xml" uri="antlib:fr.jayasoft.ivy.ant"> <classpath> <fileset dir="${ivy.home}"> <include name="ivy*.jar"/> <include name="lib/*.jar"/> </fileset> </classpath> </taskdef> </target> <target name="-ivy-retrieve" depends="-ivy-define" xmlns:ivy="antlib:fr.jayasoft.ivy.ant"> <ivy:retrieve/> <pathconvert property="ivy.classpath.computed" dirsep="/" pathsep=":"> <path> <fileset dir="lib" includes="*.jar"/> </path> <map from="${basedir}${file.separator}" to=""/> </pathconvert> <propertyfile file="nbproject/project.properties"> <entry operation="=" key="ivy.classpath" value="${ivy.classpath.computed}"/> </propertyfile> </target> <target name="-pre-compile" depends="-ivy-retrieve"/> <target name="-pre-compile-single" depends="-ivy-retrieve"/> <target name="-post-clean"> <delete dir="lib"/> </target>
5. nbproject/private/private.properties を編集しどこに Ivy がインストールされているのかを設定します。
ivy.home=/opt/ivy-1.3-RC2
(他の人が別の環境で CVS からこのプロジェクトをチェックアウトした場合、private.properties を一緒にするか、Ant のクラスパスに Ivy とライブラリを入れる必要があります)
(別の方法として netbeans/5.5/build.properties に上の行を追加し、すべての NetBeans プロジェクトで有効にできます)
6. nbproject/project.properties を編集し定義を変更します:
javac.classpath=${ivy.classpath}
7. 例えば、以下のように新規のライブラリを使ってみてください。
package ivytest; import org.dom4j.tree.DefaultElement; public class Main { public static void main(String[] args) { System.out.println(new DefaultElement("hello").asXML()); } }
8. 主プロジェクトを実行 ボタンを押すと最初は失敗します。ライブラリを読み込むためです。2回目は次のように表示されるはずです
init: deps-jar: Created dir: /tmp/ivytest/build/classes :: Ivy 1.3-RC2 - 20060215154027 :: http://ivy.jayasoft.org/ :: no configuration file found, using default... :: configuring :: url = jar:file:/opt/ivy-1.3-RC2/ivy-1.3-RC2.jar!/fr/jayasoft/ivy/conf/ivyconf.xml :: resolving dependencies :: [Ivytest|Working@m2] confs: [Default] found [Dom4j|1.6] in default :: resolution report :: --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | default | 1 | 0 | 0 | 0 || 1 | 0 | --------------------------------------------------------------------- :: retrieving :: [Ivytest] confs: [Default] 1 artifacts copied, 0 already retrieved Updating property file: /tmp/ivytest/nbproject/project.properties Compiling 1 source file to /tmp/ivytest/build/classes compile: run: <hello/> BUILD SUCCESSFUL (total time: 2 seconds)
9. ivy.xml のみを変更してクリーンビルドをするとクラスパスは自動的に更新されることに注意してください。ライブラリマネージャーなどでクラスパスのエントリはプロパティー ダイアログから追加はできますが Ivy とは別になります。
例: 以下のように追加し、
<dependency org="apache" name="commons-collections" rev="3.1"/>
ソースコードには次のように追加してみます。
System.out.println(new org.apache.commons.collections.ArrayStack());
ビルド後 実行 をすると以下のように表示されます。
<hello/> []
簡単でしょ??
バージョン: NetBeans 5.0
- 日本語訳 : Masaki Katakai
- 英文 (翻訳したバージョン: 3)
- 日本語 NetBeans ユーザー FAQ へ戻る