tags:

views:

1028

answers:

1

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.

+1  A: 

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"/>
Jason Day
Thanks, I ended up writing my own task :)
Swordfish