示例说明如何使用文件系统parsing器

任何人都可以解释我如何使用Ivy的文件系统parsing器与示例考虑..

  1. 我有ivy.xml文件,我已经定义了所有的依赖,但我想从我的文件系统不是来自maven存储库的jar子..?

  2. 我在哪里把ivysettings.xml文件。

  3. 什么build.xml应该包含使用ivysettings.xml,以便我可以使用从文件系统不是来自maven的jar子..

ivysettings.xml文件默认位于与ivy.xml文件相同的目录中。

可以使用常春藤设置任务指定替代地点

项目结构

位于lib目录中的第三方依赖项。

$ tree . |-- build.xml |-- ivysettings.xml |-- ivy.xml |-- lib | |-- junit-4.10.jar | |-- slf4j-api-1.6.4.jar | `-- slf4j-simple-1.6.4.jar `-- src |-- main | `-- java | `-- org | `-- demo | `-- App.java `-- test `-- java `-- org `-- demo `-- AppTest.java 10 directories, 8 files 

的ivy.xml

这个常青藤文件使用configuration来pipe理3种依赖关系:

  1. 运行
  2. testing

这些将对应于ANT构build使用的类path。

 <ivy-module version="2.0"> <info organisation="com.myspotontheweb" module="demo"/> <configurations defaultconfmapping="compile->default"> <conf name="compile" description="Required to compile application"/> <conf name="runtime" description="Additional run-time dependencies" extends="compile"/> <conf name="test" description="Required for test only" extends="runtime"/> </configurations> <dependencies> <!-- compile dependencies --> <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4"/> <!-- runtime dependencies --> <dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="runtime->default"/> <!-- test dependencies --> <dependency org="junit" name="junit" rev="4.10" conf="test->default"/> </dependencies> </ivy-module> 

ivysettings.xml

没什么奇特的。 简单的映射到位于lib目录下的jar:

 <ivysettings> <settings defaultResolver="local"/> <resolvers> <filesystem name="local"> <artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/> </filesystem> </resolvers> </ivysettings> 

另外…..我会永远包括非本地jar子的Maven中央回购如下:

 <ivysettings> <settings defaultResolver="central"/> <resolvers> <ibiblio name="central" m2compatible="true"/> <filesystem name="local"> <artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/> </filesystem> </resolvers> <modules> <module organisation="org.slf4j" resolver="local"/> <module organisation="junit" name="junit" resolver="local"/> </modules> </ivysettings> 

模块部分指定应该在本地检索哪些jar子。

build.xml文件

最后是使用ivy来pipe理类path的构build逻辑。

 <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant"> <!-- ================ Build properties ================ --> <property name="src.dir" location="src/main/java"/> <property name="test.src.dir" location="src/test/java"/> <property name="build.dir" location="build"/> <property name="classes.dir" location="${build.dir}/classes"/> <property name="test.classes.dir" location="${build.dir}/test-classes"/> <property name="ivy.reports.dir" location="${build.dir}/ivy-reports"/> <property name="test.reports.dir" location="${build.dir}/test-reports"/> <!-- =========== Build setup =========== --> <target name="init"> <ivy:resolve/> <ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/> <ivy:cachepath pathid="compile.path" conf="compile"/> <ivy:cachepath pathid="runtime.path" conf="runtime"/> <ivy:cachepath pathid="test.path" conf="test"/> <mkdir dir="${classes.dir}"/> <mkdir dir="${test.classes.dir}"/> <mkdir dir="${test.reports.dir}"/> </target> <!-- =============== Compile targets =============== --> <target name="compile" depends="init"> <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true" classpathref="compile.path"/> </target> <target name="compile-tests" depends="compile"> <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" debug="true"> <classpath> <path refid="test.path"/> <pathelement path="${classes.dir}"/> </classpath> </javac> </target> <!-- ============ Test targets ============ --> <target name="test" depends="compile-tests"> <junit printsummary="yes" haltonfailure="yes"> <classpath> <path refid="test.path"/> <pathelement path="${classes.dir}"/> <pathelement path="${test.classes.dir}"/> </classpath> <formatter type="xml"/> <batchtest fork="yes" todir="${test.reports.dir}"> <fileset dir="${test.src.dir}"> <include name="**/*Test*.java"/> <exclude name="**/AllTests.java"/> </fileset> </batchtest> </junit> </target> <!-- ===================== Build and run targets ===================== --> <target name="build" depends="test"/> <target name="run" depends="build"> <java classname="org.demo.App"> <classpath> <path refid="runtime.path"/> <pathelement location="${classes.dir}"/> </classpath> </java> </target> <!-- ============= Clean targets ============= --> <target name="clean"> <delete dir="${build.dir}"/> </target> <target name="clean-all" depends="clean"> <ivy:cleancache/> </target> </project> 

如果你只是在本地拉jar,而不想使用Maven Central,常春藤是浪费你的时间。 只要把你需要的任何jar子放在你的/ lib文件夹中,把它添加到你的类path中,然后运行你的Ant文件即可。 常春藤是与Maven中央互动。 但是,如果你们需要这样做,从Maven拉出普通jar子,从当地拉第三方jar子,马克的解决scheme是一个很好的解决scheme。