How to Detect Whether Tomcat and Ant Are Installed on Linux Machine

How to detect whether tomcat and ant are installed on linux machine

Generally, you can check whether they are on the $PATH, if they are not on the $PATH, install one.

For ant:

ant -v stands for verbose, ant -version prints out its version.

   -help, -h
print help on the command line options

-projecthelp, -p
gives information on possible targets for this project

-version
prints the version number and then exits ant

-quiet, -q
be extra quiet

-verbose, -v
be extra verbose

-debug, -d
print debugging information

-emacs, -e
produce logging information without adornments

-logfile <file>, -l <file>
use the given file to output log to

-logger <classname>
the class which is to perform logging

-listener <classname>
add an instance of the given class as a project listener

-noinput
do not allow interactive input

-buildfile <file>, -file <file>, -f <file>
use the given buildfile instead of the default build.xml file.
This is the ant equivalent of Makefile

-D<property>=<value>
use value for the given property

-keep-going, -k
execute all targets that do not depend on failed target(s)

-propertyfile <file>
load all properties from file with -D properties taking prece-
dence

-inputhandler <class>
the class which will handle input requests

-find <file>, -s <file>
(s)earch for buildfile towards the root of the filesystem and
use it

-nice number
A niceness value for the main thread: 1 (lowest) to 10 (high-
est); 5 is the default

-nouserlib
Run ant without using the jar files from ${user.home}/.ant/lib

-noclasspath
Run ant without using CLASSPATH

-autoproxy
Java 1.5+ : use the OS proxies

-main <class>
override ant's normal entry point

For tomcat:

if tomcat/bin is on the $PATH variable, version.sh will print out the version.

how to detect tomcat version installed and set CATALINA_HOME env variable using Ant Apache script?

If I understand correctly, you are executing this OS detection from Ant. In that case, can you not instead use Ant's built-in support for OS identification - in the os condition?

However, if you really need to execute catalina.bat while setting CATALINA_HOME, you could do so using a nested env element in you exec task.

Here is a sample build file which uses both approaches:

<project default="test">

<target name="test">

<!-- Execute a command, in this case a simple bat file
which echoes the value of the var set in the env block
-->
<exec executable="cmd">
<arg value="/c"/>
<arg value="test.bat"/>
<env key="CATALINA_HOME" value="whatever"/>
</exec>

<!-- echo the values of built-in OS related properties -->
<echo message="os.arch: ${os.arch}"/>
<echo message="os.name: ${os.name}"/>
<echo message="os.version: ${os.version}"/>

<!-- test one of the os conditions -->
<condition property="is.windows">
<os family="windows"/>
</condition>
<echo message="is.windows ? ${is.windows}"/>

</target>

</project>

Here is the content of test.bat:

echo CATALINA_HOME=%CATALINA_HOME%

Here is the output:

test:
[exec]
[exec] C:\tmp\ant>echo CATALINA_HOME=whatever
[exec] CATALINA_HOME=whatever
[echo] os.arch: x86
[echo] os.name: Windows XP
[echo] os.version: 6.1 build 7601 Service Pack 1
[echo] is.windows ? true

Regarding your subsequent question (in comments) about tomcat version...

I now guess you are executing this version detection via Ant in your runtime environment.

Ant and Java don't know about your Tomcat environment, so now you're back to executing %CATALINA_HOME%\bin\catalina.bat -version and parsing what you need from the output.

Here's a working example:

<project default="version">
<property environment="env"/>

<condition property="script.ext" value="bat">
<os family="windows"/>
</condition>
<condition property="script.ext" value="sh">
<os family="unix"/>
</condition>

<target name="version">
<exec executable="${env.CATALINA_HOME}/bin/version.${script.ext}" outputproperty="tomcat.version">
<redirector>
<outputfilterchain>
<tokenfilter>
<containsstring contains="Server version"/>
<replaceregex pattern="Server version: Apache Tomcat/(.*)$" replace="\1"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<echo message="tomcat.version: ${tomcat.version}"/>
</target>
</project>

And here is the output:

version:
[echo] tomcat.version: 5.5.33

Note that this example assumes that you have the CATALINA_HOME (and JAVA_HOME) environment variable set in your terminal.

Alternatively, you could pass these variables using a nested <env> element as previously discussed. But it seems more likely that these should come from the runtime environment rather than embedded in your build file.

TeamCity deploy to Tomcat with Ant fails

Just answering the question,

Thanks to @timomeinen - adding the catalina-ant.jar to $ANT_HOME/lib did the job.



Related Topics



Leave a reply



Submit