Ant步步为营(4)ant启动tomcat

前序:

最近产品要release,一直忙着测试,没有时间学习ant了,今天终于没什么事了赶紧写点东西。这个启动tomcat是好些天之前写的了。在这里跟大家分享一下。

build.xml

<?xml version="1.0"?>
    <project name="ForTest"
default="start_tomcat" >
    <property
file="build.properties"></property>
      
 <target name="stop_tomcat">
 
       
<echo>停止tomcat</echo>
 
        <exec executable="cmd"
dir="${tomcat.home}/bin" failonerror="false" 
 
                   
output="${log.file}" append="true" >
 
           
<!-- <arg value="/c" /> -->   
 
           
<env key="CATALINA_HOME" path="${tomcat.home}"/>
  
         <arg
value="/c"/>
          
 <arg value="shutdown.bat"/> 
 
        </exec>
 
    </target>  
 

    <target name="start_tomcat" depends="stop_tomcat">
 
       
<echo>启动tomcat</echo>
 
        <exec executable="cmd"
dir="${tomcat.home}/bin"  failonerror="false" 
 
                   
output="${log.file}" append="true" >
 
            
<!-- <arg value="/c" /> -->  
 
            
<env key="CATALINA_HOME" path="${tomcat.home}"/>
 
            
<arg value="/c startup.bat" />   
 
        </exec>
 
    </target>  
  
 </project>

build.properties

tomcat.home=G:\\apache-tomcat-7.0.42-windows-x64\\apache-tomcat-7.0.42

注意几点:

exec executable="cmd"这一句是用在window系统下用cmd的方式启动tomcat。

<env key="CATALINA_HOME"
path="${tomcat.home}"/>必须指明CATALINA_HOME的值。

env是ant的数据类型,参考:http://www.cnblogs.com/xionghui/archive/2012/03/13/2393679.html

/c的解释:(参考ant api)

Windows Users

The <exec> task
delegates to Runtime.exec which in turn apparently calls ::CreateProcess. It is the latter Win32 function that defines
the exact semantics of the call. In particular, if you do not put a file
extension on the executable, only ".EXE" files are looked for, not ".COM",
".CMD" or other file types listed in the environment variable PATHEXT. That is
only used by the shell.

Note that .bat files cannot in general by
executed directly. One normally needs to execute the command shell executable
cmd using the /c switch.

<target name="help">
<exec executable="cmd">
<arg value="/c"/>
<arg value="ant.bat"/>
<arg value="-p"/>
</exec>
</target>

A common problem is not having the
executable on the PATH. In case you get an error message Cannot run program
"...":CreateProcess error=2. The system cannot find the path specified.

have a look at your PATH variable. Just type the command directly on the command
line and if Windows finds it, Ant should do it too. (Otherwise ask on the user
mailinglist for help.) If Windows can not execute the program add the directory
of the program to the PATH (set PATH=%PATH%;dirOfProgram) or specify
the absolute path in the executable attribute in your
buildfile.

Ant步步为营(4)ant启动tomcat

时间: 2024-07-31 18:32:41

Ant步步为营(4)ant启动tomcat的相关文章

ant 打包 web项目并用tomcat启动

1.整体目录 2.配置build.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project name="ipnet" default="deleteWar" basedir="."> <property name="build" value="${basedir}/build" />

Ant步步为营(3)在svn上checkout code.

马上下班了,在发一篇吧.今天这个的时候发现好多好的网址,所以提前发了. 老规矩:build.xml <?xml version="1.0"?>    <project name="StartProduct" default="checkout.testcode" >    <property file="build.properties"></property> <!--引

Ant步步为营(2)在ftp上下载需要的文件

早上好,开始一天工作之前先踩踩了园子,今天介绍ftp上下载文件. <?xml version="1.0"?>    <project name="ForTest" default="ftp.download" >    <property file="build.properties"></property>        <target name= "ftp.d

Ant步步为营(5)用for和foreach的方法遍历一个文件夹,查找到某个文件并删除

今天有个任务是要删除VM上的某个文件夹下的两个jar包.不过这个任务没有分配给我,而是分配给俺的师傅,哈哈.不过我还是自己动手写了一些脚本在本地模拟一下删除某个指定文件. build.xml <?xml version="1.0"?>    <project name="ForTest" default="build" >    <property file="build.properties"&

eclipse启动tomcat弹出错误提示:Tomcat setting should be set in tomcat preference page

eclipse启动tomcat可能会弹出以下错误: 主要原因是tomcat没有配置好,解决方案如下: 第一步:Windows->Preference->Server->Runtime Environment然后选择自己安装的Tomcat版本,然后Next,选择Tomcat安装路径,Finish 第二步:Windows->Preference->Tomcat,选择版本及安装路径,然后Apply,最后保存退出即可 检测:启动tomcat 图解如下:

MyEclipse启动tomcat增加内存配置

omcat增加内存在catalina.bat下 MyEclipse增加内存 设置Window->Preferences->Application Servers->Tomcat --->JDK---> Optional Java VM Arguments -Xms256m -Xmx636m 然后启动tomcat就可以使用分配的内存了. 关注流行国外网站 facebook:http://www.fb-on.com facebook官网:http://www.facebookzh

eclipse启动tomcat无法访问

eclipse启动tomcat无法访问 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomcat,在tomcat安装目录下双击startup.bat手动启动tomcat服务器.访问htt://localhost:8080/能正常访问tomcat管理页面. 症状原因: eclipse将tomcat的项目发布目录(tomcat 目录中的webapp)重定

maven+SpringMVC框架开发启动tomcat报监听异常

我们在做web开发是,经常都要在eclipse中搭建web服务器,并将开发中的web项目部署到web服务器进行调试,在此,我选择的是tomcat服务器.之前部署web项目到tomcat进行启动调试都很正常,今天突然出现无法启动情况,启动过程报如下错误: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener    at org.apache.catalina.loader.We

开机启动tomcat

windows: 成功之后在dos窗口键入 service.bat install Tomcat 输完然后按Enter键,出现如下窗口,便成功了. 进入windows服务管理,设成是自动的. #chkconfig --add myservice linux: 常常会出现 service myservice does not support chkconfig 我们一般在脚本开头加入下面两句就好了 #gedit /etc/init.d/myservice 添加下面两句到 #!/bin/bash 之