Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd suggest using <a href="http://ant.apache.org/ivy/" rel="nofollow">Apache ivy</a> for managing complex classpaths. It externalizes your build dependencies into a separate <strong>ivy.xml</strong> file.</p> <p>Secondly, ivy can automatically download such dependencies, reducing the size of your project under source control.</p> <p>Finally, this solution at first glance might appear horribly complex. It's advantage is that it's compatible with other build technologies such as <a href="http://maven.apache.org/" rel="nofollow">Maven</a>.</p> <h1>Example</h1> <h2>ivy.xml</h2> <p>Ivy uses "configurations" to manage logical groupings of jars. </p> <p>In this example the code compiles against the SLF4J api jars, but at run-time use different logging implementations:</p> <pre><code>&lt;ivy-module version="2.0"&gt; &lt;info organisation="com.myspotontheweb" module="demo"/&gt; &lt;configurations&gt; &lt;conf name="compile" description="Required to compile application"/&gt; &lt;conf name="runtime.simple" description="Runtime environment with minimal logging" extends="compile"/&gt; &lt;conf name="runtime.complex" description="Runtime environment with logback enabled" extends="compile"/&gt; &lt;conf name="test" description="Required for test only" extends="runtime.simple"/&gt; &lt;conf name="build" description="ANT tasks used by build"/&gt; &lt;/configurations&gt; &lt;dependencies&gt; &lt;!-- compile dependencies --&gt; &lt;dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile-&gt;default"/&gt; &lt;!-- simple runtime dependencies --&gt; &lt;dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="runtime.simple-&gt;default"/&gt; &lt;!-- complex runtime dependencies --&gt; &lt;dependency org="ch.qos.logback" name="logback-classic" rev="1.0.3" conf="runtime.complex-&gt;default"/&gt; &lt;!-- test dependencies --&gt; &lt;dependency org="junit" name="junit" rev="4.10" conf="test-&gt;default"/&gt; &lt;!-- Build dependencies --&gt; &lt;dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.6" conf="build-&gt;default"/&gt; &lt;/dependencies&gt; &lt;/ivy-module&gt; </code></pre> <p><strong>Notes:</strong></p> <ul> <li>The <strong>extends</strong> attribute enables the creation of jar union sets</li> <li>By default ivy will download from <a href="http://search.maven.org/" rel="nofollow">Maven Central</a> (an open repository that now hosts approx 90% of Java open source software). </li> <li>Using the <strong>conf</strong> attribute you can associated a depedency against one or more of your locally defined configurations.</li> <li>Ivy can also be used to manage 3rd party ANT task dependencies</li> </ul> <h2>build.xml</h2> <p>The ivy ANT tasks are imported as an <a href="http://ant.apache.org/manual/Types/antlib.html" rel="nofollow">antlib</a>. The ivy <a href="http://ant.apache.org/ivy/history/latest-milestone/use/cachepath.html" rel="nofollow">cachepath</a> task is used to turn an ivy managed configuration into normal ANT <a href="http://ant.apache.org/manual/using.html#path" rel="nofollow">paths</a> and the ivy <a href="http://ant.apache.org/ivy/history/latest-milestone/use/report.html" rel="nofollow">report</a> task produces a dependency report.</p> <pre><code>&lt;project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant"&gt; &lt;target name="init"&gt; &lt;ivy:resolve/&gt; &lt;ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/&gt; &lt;ivy:cachepath pathid="compile.path" conf="compile"/&gt; &lt;ivy:cachepath pathid="runtime.simple.path" conf="runtime.simple"/&gt; &lt;ivy:cachepath pathid="runtime.complex.path" conf="runtime.complex"/&gt; &lt;ivy:cachepath pathid="test.path" conf="test"/&gt; &lt;ivy:cachepath pathid="build.path" conf="build"/&gt; &lt;/target&gt; .. .. </code></pre> <p>The ivy <a href="http://ant.apache.org/ivy/history/latest-milestone/use/retrieve.html" rel="nofollow">retrieve</a> task is used to populate a directory during your application's packaging phase:</p> <pre><code>&lt;target name="war"&gt; &lt;ivy:retrieve pattern="${build.dir}/libs/[artifact].[ext]" conf="runtime.complex"/&gt; &lt;war destfile="myapp.war" webxml="src/metadata/myapp.xml"&gt; &lt;fileset dir="${src.dir}/html/myapp"/&gt; &lt;fileset dir="${src.dir}/jsp/myapp"/&gt; &lt;lib dir="${build.dir}/libs"/&gt; &lt;classes dir="${build.dir}/classes"/&gt; &lt;/war&gt; &lt;/target&gt; </code></pre> <h1>IDE configuration files</h1> <p>An <a href="http://ant.apache.org/ivy/ivyde/" rel="nofollow">Eclipse plugin</a> for ivy is available.</p> <ul> <li><a href="http://ant.apache.org/ivy/ivyde/" rel="nofollow">http://ant.apache.org/ivy/ivyde/</a></li> </ul> <p>It's also possible to generate IDE configuration files using an embedded <a href="http://groovy.codehaus.org/The+groovy+Ant+Task" rel="nofollow">groovy</a> task. Following is an Eclipse example:</p> <pre><code>&lt;target name="eclipse"&gt; &lt;taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/&gt; &lt;ivy:cachefileset setid="libfiles" conf="compile"/&gt; &lt;groovy&gt; &lt;arg value="${src.dir}"/&gt; &lt;arg value="${build.dir}/classes"/&gt; import groovy.xml.MarkupBuilder // // Generate the project file // project.log("Creating .project") new File(".project").withWriter { writer -&gt; def xml = new MarkupBuilder(writer) xml.projectDescription() { name(project.name) comment() projects() buildSpec() { buildCommand() { name("org.eclipse.jdt.core.javabuilder") arguments() } } natures() { nature("org.eclipse.jdt.core.javanature") } } } // // Generate the classpath file // // The "lib" classpathentry fields are populated using the ivy artifact report // project.log("Creating .classpath") new File(".classpath").withWriter { writer -&gt; def xml = new MarkupBuilder(writer) xml.classpath() { classpathentry(kind:"src", path:args[0]) classpathentry(kind:"output", path:args[1]) classpathentry(kind:"con", path:"org.eclipse.jdt.launching.JRE_CONTAINER") project.references.libfiles.each { classpathentry(kind:"lib", path:it) } } } &lt;/groovy&gt; &lt;/target&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload