ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hezjing <hezj...@gmail.com>
Subject Re: Create compile-time and runtime classpath
Date Thu, 05 Jul 2007 01:39:45 GMT
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 ...


On 7/4/07, Xavier Hanin <xavier.hanin@gmail.com> wrote:
> On 7/4/07, hezjing <hezjing@gmail.com> wrote:
> >
> > Hi!
> >
> > With Ivy, we use <ivy:cachepath> to construct the classpath. I think
> > this will build a classpath containing all the dependencies in the
> > cache (correct?).
>
>
> Correct.
>
> How can we create, say a compile-time classpath and runtime classpath
> > from the Ivy cache?
> >
> > Example, if there are A.jar; B.jar; C.jar; D.jar; E.jar in the cache,
> > how do I create a compile-time classpath which contains A.jar + B.jar,
> > and a runtime classpath of A.jar + B.jar + E.jar?
> >
> >
> > Before Ivy, we used to create two path-like structures shown below,
> >
> > <path id="compile.cp">
> > <pathelement location="lib/A.jar" />
> > <pathelement location="lib/B.jar" />
> > </path>
> >
> > <path id="runtime.cp">
> > <pathelement location="bin" />
> > <pathelement location="lib/A.jar" />
> > <pathelement location="lib/B.jar" />
> > <pathelement location="lib/E.jar" />
> > </path>
>
>
> You have several options here. The best is to use Ivy configurations:
> declare one compile and one runtime configuration, and map your dependencies
> in those configurations. Then you can call resolve to resolve both
> configurations, and call cachepath twice, one for each configuration. You
> will get what you want except the bin directory, so you'll still have to
> build your real runtime.cp refering to the cp created by ivy:cachepath and
> to your bin directory.
>
> The other option is to use the retrieve task to copy your dependencies to
> your lib directory, and build your classpath using regular Ant classpath
> mechanisms. If you use configurations as above it can be very simple, use
> the [conf] token when you call retrieve, then you will have your jars split
> in conf directories, and it will be easy to create your paths.
>
> Which option to choose is a matter of taste, disk space and performances
> (retrieve require an additonal copy).
>
> HTH,
>
> Xavier
>
> --
> >
> > Hez
> >
>
>
>
> --
> Xavier Hanin - Independent Java Consultant
> http://xhab.blogspot.com/
> http://incubator.apache.org/ivy/
> http://www.xoocode.org/
>


-- 

Hez

Mime
View raw message