Ant: check if the class exists in the bank

How can I check if a particular class exists in the jar file? I tried the available task and it doesn't seem to work

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

For example, I want to check if a match pattern exists **/xyz/foo.class

in foobar.jar

Any direction taken.

+1


a source to share


1 answer


The accessible task should work if you give it the exact class name. Here's 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 for a pattern, let alone my own problem. I think you could use the unjar task to extract the template to a temporary directory and then check if the file exists. For instance:

<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"/>

      

+2


a source







All Articles