...">

Run tomcat from ant script

I use the following ANT script to run tomcat:

<macrodef name="start-tomcat"> <sequential> <exec executable="/bin/sh" > <arg value="-c" /> <arg value='${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M' /> </exec> </sequential> </macrodef> 

when I run the tomcat script from the shell, tomcat starts normally, and I see this output:

 Using CATALINA_BASE: /u/app Using CATALINA_HOME: /u/app/3rdparty/apache-tomcat-6.0.33 Using CATALINA_TMPDIR: /u/app/temp Using JRE_HOME: /usr/java/jre1.6.0_13 Using CLASSPATH: /u/app/3rdparty/apache-tomcat-6.0.33/bin/bootstrap.jar 

I have two problems:

  • How can I tell ANT to show me the output as above? ANT only shows output when there is an error.
  • When I run the build.xml file from the shell with the ANT executable tomcat, it starts. when you run the build file through the CI server - in particular, Jenkins (Hudson) tomcat does NOT start.

I find it difficult to understand how to use the <exec> task to run shell scripts, is there something I am doing wrong?

Thanks.

+4
source share
3 answers

The problem is with the Jenkins function called ProcessTreeKiller described here .

In principle, Jenkins automatically kills all the processes generated by the task by searching in the process tree for processes with a specific environment variable

All I had to do was overwrite the env jenkins variable called BUILD ID and it worked. I used Setenv Plugin to install env var for assembly.

+2
source

How about executing the command as follows:

 <exec executable="bash" > <arg value="-c" /> <arg value='nohup ${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M &' /> </exec> 
+1
source
 Here is how you can stop tomcat from Ant script: 

build.properties file:

  #---------------------------------------------------- #Tomcat Configuration #---------------------------------------------------- #Back-end Tomcat tomcat.dir=${branch.dir}/../tomcat tomcat.bin.dir=${tomcat.dir}/bin tomcat.bootstrap.jar=${tomcat.bin.dir}/bootstrap.jar tomcat.jvmarg=-Dcatalina.home 

loadproperties file

  <property file="${basedir}/build.properties" /> <!-- Stop tomcat --> <target name="stop-tomcat" description="Stops back-end tomcat server" depends="prepare"> <java jar="${tomcat.bootstrap.jar}" fork="true" spawn="false"> <jvmarg value="${tomcat.jvmarg}=${tomcat.dir}" /> <arg line="${arg.stop}" /> </java> <echo>+---------------------------------+</echo> <echo>| TOMCATSTOPPED |</echo> <echo>+---------------------------------+</echo> </target> Also I have added an element called spawn set to "false", which print execution output onto console. Hope this helps :) 
+1
source

All Articles