从ant脚本启动tomcat

时间:2011-10-09 11:25:02

标签: tomcat ant hudson jenkins

我正在使用以下ANT脚本来运行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>

当我从shell运行tomcat启动脚本时,tomcat正常启动,我看到这样的输出:

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

我有两个问题:

  1. 我如何告诉蚂蚁向我展示如上所述的输出? ant只在出现错误时显示输出。
  2. 当我从shell运行带有ant可执行文件tomcat的build.xml文件时,启动了。通过CI服务器运行构建文件时 - 特别是Jenkins(Hudson)tomcat没有启动。
  3. 我发现很难理解如何使用<exec>任务来运行shell脚本,我有什么问题吗?

    感谢。

3 个答案:

答案 0 :(得分:2)

问题与名为here的名为ProcessTreeKiller的Jenkins功能有关。

基本上,Jenkins通过在进程树中搜索具有特定环境变量的进程来自动杀死作业生成的所有进程

我所要做的就是覆盖名为BUILD ID的jenkins env变量并且它有效。 我使用Setenv Plugin来设置构建的特定env var。

答案 1 :(得分:1)

如下所示执行命令:

<exec executable="bash" >
            <arg value="-c" />
            <arg value='nohup ${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M &' />
</exec>

答案 2 :(得分:1)

Here is how you can stop tomcat from Ant script: 

build.properties文件:

 #----------------------------------------------------
 #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文件

 <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>|   T O M C A T   S T O P P E D   |</echo>
    <echo>+---------------------------------+</echo>
</target>

Also I have added an element called spawn set to "false", which print execution output onto console. 

Hope this helps :) 
相关问题