Issue
I am trying to define a taskdef in ant for Tomcat.
<taskdef name="antStartServer" classname="org.apache.catalina.ant.StartTask" />
<taskdef name="antStopServer" classname="org.apache.catalina.ant.StopTask" />
But when I run the script, I get the error:
taskdef class org.apache.catalina.ant.StartTask cannot be found using the classloader AntClassLoader[]
Can you please tell me what I am doing wrong? I have all the jars put in the Tomcat lib folder. I am using Tomcat 9 and Ant 1.10.5
Solution
You need to specify a classpath in which Ant can find the classes you need:
<!-- set the path to Tomcat root install directory -->
<property name="tomcat.home" value="..."/>
<path id="tomcat.path">
<fileset dir="${tomcat.home}/lib" includes="*.jar"/>
</path>
<taskdef name="antStartServer" classname="org.apache.catalina.ant.StartTask" classpathref="tomcat.path"/>
<taskdef name="antStopServer" classname="org.apache.catalina.ant.StopTask" classpathref="tomcat.path"/>
Answered By - Lolo