Note that there are some explanatory texts on larger screens.

plurals
  1. POwhere to find missing optional ant tasks?
    primarykey
    data
    text
    <p>I wanted to have a look which system properties are set here (and to which values), so the easiest way (if not writing a new Java program here) would be adding some lines to my ant build script:</p> <pre><code> &lt;target name="properties"&gt; &lt;echoproperties/&gt; &lt;/target&gt; </code></pre> <p>But running ant gives my this error message:</p> <pre><code>/u/ebermann/projektoj/stackoverflow-examples/build.xml:19: Problem: failed to create task or type echoproperties Cause: the class org.apache.tools.ant.taskdefs.optional.EchoProperties was not found. This looks like one of Ant's optional components. Action: Check that the appropriate optional JAR exists in -/usr/share/ant/lib -/u/ebermann/.ant/lib -a directory added on the command line with the -lib argument Do not panic, this is a common problem. The commonest cause is a missing JAR. This is not a bug; it is a configuration problem </code></pre> <p>Okay, so I don't panic, but wonder what to do.</p> <p>I have Ant 1.7.1 here (an OpenSUSE system), and sadly no documentation for this version, and I'm not root to install either a current ant version or the documentation for the old version (I just downloaded it and it still does not say which jar file is needed here). Of the directories listed above, only <code>/usr/share/ant/lib</code> exists, but it contains nothing like <code>optional</code>. </p> <p>I would want to download the necessary jar file and put it in my home directory, but where to find it? The <a href="http://archive.apache.org/dist/ant/" rel="noreferrer">ant download archive</a> contains nothing like that, and I have no idea where else to search. (I did google a bit, but did not find anything.</p> <p><strong>So, can someone give me some pointers where to find the right jar file?</strong></p> <p>(I suppose the solution is quite easy, and something is just blocking my view.)</p> <hr> <p>After <em>vahapt</em>'s answer, I downloaded the file from the <a href="https://repository.apache.org/content/repositories/releases/org/apache/ant/ant-nodeps/1.7.1/" rel="noreferrer">apache repository</a>, and put it into the directory <code>/u/ebermann/.ant/lib</code> mentioned by the error message. Running <code>ant properties</code> again - the same result as above.</p> <pre><code>$ jar -tf /u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar | grep 'EchoProperties.class' org/apache/tools/ant/taskdefs/optional/EchoProperties.class </code></pre> <p>This looks like it should work - is the error message simply wrong?</p> <p>If I put it directly into the CLASSPATH, it works:</p> <pre><code>$ CLASSPATH=/u/ebermann/.ant/lib/ant-nodeps-1.7.1.jar ant properties Buildfile: build.xml properties: [echoproperties] #Ant properties [echoproperties] #Thu Mar 10 00:46:22 CET 2011 ... [echoproperties] user.name=ebermann [echoproperties] user.timezone= BUILD SUCCESSFUL Total time: 0 seconds </code></pre> <p>I don't want to change my normal CLASSPATH variable, and it should work by putting it into this directory, or did I understand something wrong?</p> <p>Any ideas, or is this an ant bug?</p> <p>(Also, why is this file nowhere mentioned in the ant documentation?)</p> <hr> <p>Edit:</p> <p>After the answer from <em>vahapt</em>, my ant build-file looks like this:</p> <pre><code>&lt;project name="stackoverflow-examples" basedir="."&gt; &lt;target name="echoproperties.prepare"&gt; &lt;available property="echoproperties.works" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties" /&gt; &lt;/target&gt; &lt;target name="echoproperties.init" depends="echoproperties.prepare" unless="echoproperties.works"&gt; &lt;taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties"&gt; &lt;classpath&gt; &lt;fileset dir="${user.home}/.ant/lib"&gt; &lt;include name="ant-nodeps.jar" /&gt; &lt;/fileset&gt; &lt;/classpath&gt; &lt;/taskdef&gt; &lt;/target&gt; &lt;target name="properties" depends="echoproperties.init"&gt; &lt;echoproperties/&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>This re-registers the task only if it is not already in the ant classpath. (Thus it should also work for complete ant installations which do not have this file in the home directory).</p> <p>I would still say that <code>This is not a bug; it is a configuration problem</code> is not totally right, even more as putting the file in the indicated directory <strong>does <em>not</em> help</strong>.</p> <hr> <p>One more interesting observation: The nodeps.jar in <code>${user.home}/.ant/lib</code> (i.e. now <code>/u/ebermann/.ant/lib/ant-nodeps.jar</code>) <em>is already in the class path</em> (the one shown by <code>${java.class.path}</code>, but this seems not to help for <code>&lt;echoproperties&gt;</code> to work without this <code>taskdef</code>.</p> <p>So, this works too:</p> <pre><code> &lt;target name="echoproperties.init" depends="echoproperties.prepare" unless="echoproperties.works"&gt; &lt;taskdef name="echoproperties" classname="org.apache.tools.ant.taskdefs.optional.EchoProperties" classpath="${java.class.path}" /&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.
 

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