Question

How do I check if a particular class exists in a jar file? I tried available task and it does not seem to work

If there is a way, can I use patterns in it?

For example, I want to check if a class matching pattern **/xyz/foo.class exists in foobar.jar

Any direction appreciated.

Was it helpful?

Solution

The Available task should work, if you give it the exact class name. Here is an example from the Ant manual for available:

...in project ...
<property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/>
<path id="jaxp" location="${jaxp.jar}"/>
...in target ...
<available classname="javax.xml.transform.Transformer"
           classpathref="jaxp" property="jaxp11.present"/>

I don't know of any way to search based on a pattern, short of writing your own task. I guess you could use the unjar task to extract the pattern to a temporary directory, and then check if the file exists. For example:

<property name="temp.dir" value="some_temp_directory"/>
<unjar src="foobar.jar" dest="${temp.dir}">
    <patternset>
        <include name="**/xyz/foo.class"/>
    </patternset>
    <mapper type="flatten"/>
</unjar>
<available property="foo.present" file="${temp.dir}/foo.class"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top