从ant脚本启动tomcat

发布于 2024-12-08 15:48:49 字数 967 浏览 0 评论 0原文

我正在使用以下 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 显示如上所述的输出? ant 仅在出现错误时显示输出。
  2. 当我使用 ant 可执行文件从 shell 运行 build.xml 文件时,tomcat 会启动。通过 CI 服务器运行构建文件时 - 特别是 Jenkins (Hudson) tomcat 不会启动。

我发现很难理解如何使用 任务来运行 shell 脚本,我做错了什么吗?

谢谢。

i'm using 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 startup script from shell, tomcat starts normally and I see an output like this:

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:

  1. How can I tell ant to show me output like the above ? ant only shows me output when there is error.
  2. When i'm running the build.xml file from shell with ant executable tomcat does start up. when running the build file through a CI server - specifically Jenkins (Hudson) tomcat DOESN'T starts up.

I'm finding it hard to understand how to use the <exec> task to run shell scripts, is there anything i'm doing wrong ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

用心笑 2024-12-15 15:48:49

该问题与此处描述的名为 ProcessTreeKiller 的 Jenkins 功能有关。一个>。

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

。我所要做的就是覆盖名为 BUILD ID 的 jenkins env 变量,它就起作用了。
我使用 Setenv 插件 来设置特定于构建的环境变量。

The problem had to do with Jenkins feature called ProcessTreeKiller described here.

Basically Jenkins automatically kills all processes spawned by a job by searching the process tree for processes with specific environment variable

All i had to do was to overwrite jenkins env variable called BUILD ID and it worked.
I used a Setenv Plugin to set the env var specific for the build.

豆芽 2024-12-15 15:48:49

执行这样的命令怎么样:

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

What about executing the command like this :

<exec executable="bash" >
            <arg value="-c" />
            <arg value='nohup ${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M &' />
</exec>
摘星┃星的人 2024-12-15 15:48:49
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 :) 
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>|   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 :) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文