On 7/5/07, hezjing <[EMAIL PROTECTED]> wrote:

To summarize, the following resolved the problem using Ivy
configuration as suggested by Xavier.

The compile.cp contains only slf4j-api-1.4.0.jar, whereas runtime.cp
contains slf4j-api-1.4.0.jar, slf4j-log4j12-1.4.0.jar and
log4j-1.2.14.jar.

ivy.xml:
<ivy-module version="1.0">
  <info organisation="jayasoft" module="hello-ivy" />
  <configurations>
    <conf name="compile" />
    <conf name="runtime" extends="compile" />
  </configurations>
  <dependencies>
    <dependency org="org.slf4j" name="slf4j-api" rev="1.4.0"
conf="compile->default" />
    <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.4.0"
conf="runtime->default" />
    <dependency org="log4j" name="log4j" rev="1.2.14"
conf="runtime->default" />
  </dependencies>
</ivy-module>

build.xml:
project xmlns:ivy="antlib:fr.jayasoft.ivy.ant" name="hello-ivy">
  <target name="resolve">
    <ivy:retrieve />
  </target>
  <target name="init" depends="resolve">
    <ivy:cachepath pathid="compile.cp" conf="compile" />
    <ivy:cachepath pathid="runtime.cp" conf="runtime" />
  </target>
  <target name="compile" depends="init">
    <mkdir dir="bin" />
    <javac srcdir="src/main/java" destdir="bin" fork="true"
source="1.5" target="1.5">
      <classpath refid="compile.cp" />
    </javac>
  </target>
  <target name="run" depends="compile">
    <java classname="Test" fork="true">
      <classpath>
        <pathelement path="bin"/>
        <pathelement path="src/main/resource"/>
        <path refid="runtime.cp" />
      </classpath>
    </java>
  </target>
  <target name="clean-all">
    <delete dir="bin" />
    <delete dir="${user.home}/.ivy/cache" />
  </target>
</project>


One question is that why I have to put conf="compile->default" and
conf="runtime->default" to make it works? Without the "->default", it
will give error ...


because by default a configuration is mapped to itself, so 'compile' <==>
'compile->compile', but the dependency does not define a compile
configuration, so it doesn't work. You can change the default mapping in a
module by using defaultConfMapping, for instance
defaultConfMapping="*->default", if you want any configuration to be mapped
to 'default' by default.

Xavier

--
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://incubator.apache.org/ivy/
http://www.xoocode.org/

Reply via email to