I've installed and set up
Tomcat 7.0.21. I followed Tomcat 7.0 documentation on using the special tasks List, Reload, Install, and Remove. Here's the build.xml snippet:
<path id="compile.classpath">
<fileset dir="${catalina.home}/bin"><include name="*.jar"/></fileset>
<fileset dir="${catalina.home}/lib"><include name="*.jar"/></fileset>
</path>
<echo message="${toString:compile.classpath}"/>
<taskdef resource="org/apache/catalina/ant/catalina.tasks" classpathref="compile.classpath"/>
Here's what happens when I try to execute any of the special tasks i.e. List:
[pgarner@localhost Patrac]$
ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[pgarner@localhost Patrac]$ echo $CLASSPATH
[pgarner@localhost Patrac]$ ant list
Buildfile: /home/pgarner/workarea/Patrac/build.xml
[echo] /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/commons-daemon.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/tomcat/lib/annotations-api.jar:/usr/share/tomcat/lib/catalina-ant.jar:/usr/share/tomcat/lib/catalina-ha.jar:/usr/share/tomcat/lib/catalina-tribes.jar:/usr/share/tomcat/lib/catalina.jar:/usr/share/tomcat/lib/ecj-3.7.jar:/usr/share/tomcat/lib/el-api.jar:/usr/share/tomcat/lib/jasper-el.jar:/usr/share/tomcat/lib/jasper.jar:/usr/share/tomcat/lib/jsp-api.jar:/usr/share/tomcat/lib/postgresql-9.1-901.jdbc4.jar:/usr/share/tomcat/lib/servlet-api.jar:/usr/share/tomcat/lib/tomcat-api.jar:/usr/share/tomcat/lib/tomcat-coyote.jar:/usr/share/tomcat/lib/tomcat-dbcp.jar:/usr/share/tomcat/lib/tomcat-i18n-es.jar:/usr/share/tomcat/lib/tomcat-i18n-fr.jar:/usr/share/tomcat/lib/tomcat-i18n-ja.jar:/usr/share/tomcat/lib/tomcat-jdbc.jar:/usr/share/tomcat/lib/tomcat-util.jar
Trying to override old definition of datatype resources
list:
BUILD FAILED
/home/pgarner/workarea/Patrac/build.xml:481: java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/B2CConverter
As you can see, all three of $CATALINA_HOME/lib/catalina-ant.jar:$CATALINA_HOME/lib/tomcat-coyote.jar:$CATALINA_HOME/lib/tomcat-util.jar:$CATALINA_HOME/bin/tomcat-juli.jar appear in the class path, above, which I echoed from within Ant. Now, watch this:
[pgarner@localhost Patrac]$ export CLASSPATH=".:$CATALINA_HOME/lib/catalina-ant.jar:$CATALINA_HOME/lib/tomcat-coyote.jar:$CATALINA_HOME/lib/tomcat-util.jar:$CATALINA_HOME/bin/tomcat-juli.jar"
[pgarner@localhost Patrac]$ echo $CLASSPATH
.:/usr/share/tomcat/lib/catalina-ant.jar:/usr/share/tomcat/lib/tomcat-coyote.jar:/usr/share/tomcat/lib/tomcat-util.jar:/usr/share/tomcat/bin/tomcat-juli.jar
[pgarner@localhost Patrac]$ ant list
Buildfile: /home/pgarner/workarea/Patrac/build.xml
[echo] /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/commons-daemon.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/tomcat/lib/annotations-api.jar:/usr/share/tomcat/lib/catalina-ant.jar:/usr/share/tomcat/lib/catalina-ha.jar:/usr/share/tomcat/lib/catalina-tribes.jar:/usr/share/tomcat/lib/catalina.jar:/usr/share/tomcat/lib/ecj-3.7.jar:/usr/share/tomcat/lib/el-api.jar:/usr/share/tomcat/lib/jasper-el.jar:/usr/share/tomcat/lib/jasper.jar:/usr/share/tomcat/lib/jsp-api.jar:/usr/share/tomcat/lib/postgresql-9.1-901.jdbc4.jar:/usr/share/tomcat/lib/servlet-api.jar:/usr/share/tomcat/lib/tomcat-api.jar:/usr/share/tomcat/lib/tomcat-coyote.jar:/usr/share/tomcat/lib/tomcat-dbcp.jar:/usr/share/tomcat/lib/tomcat-i18n-es.jar:/usr/share/tomcat/lib/tomcat-i18n-fr.jar:/usr/share/tomcat/lib/tomcat-i18n-ja.jar:/usr/share/tomcat/lib/tomcat-jdbc.jar:/usr/share/tomcat/lib/tomcat-util.jar
Trying to override old definition of datatype resources
list:
[list] OK - Listed applications for virtual host localhost
[list] /manager:running:0:manager
[list] /:running:0:ROOT
[list] /docs:running:0:docs
[list] /examples:running:0:examples
[list] /host-manager:running:0:host-manager
BUILD SUCCESSFUL
Total time: 3 seconds
Why can the List target not see the needed JAR files on its class path unless I set it in my Linux user environment? I don't want to have to add an export CLASSPATH entry in .bash_profile. I should be able to set the class path for executing an Ant task inside of an Ant build script. What am I not understanding here?