Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant check classpath for jar before taskdef

Tags:

ant

Is there a way to check the classpath for a jar before executing a taskdef.

For example, I want to surround the following with a condition that checks if a jar that can has the class org.hibernate.tool.ant.HibernateToolTask before executing the taskdef

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"  classpathref="hibernatetool-classpath" />
like image 400
user373201 Avatar asked Jan 21 '23 21:01

user373201


1 Answers

This should work:

<available 
      property="hibernatetoolok" 
      classname="org.hibernate.tool.ant.HibernateToolTask" 
      classpathref="hibernatetool-classpath" />

<target name="hibernatetool" if="hibernatetoolok">
  <taskdef 
    name="hibernatetool" 
    classname="org.hibernate.tool.ant.HibernateToolTask"  
    classpathref="hibernatetool-classpath" />
</target>

Then on any target where you use the hibernatetool task be sure to add depends="hibernatetool".

like image 160
David Avatar answered May 26 '23 01:05

David