2016-07-29 167 views
0

我需要啓動和停止使用Ant腳本的Tomcat服務器,但是我發現堆棧溢出腳本,但是當我使用它時,它會給出下面提到的錯誤。如何使用Ant腳本啓動和停止Tomcat服務器?

腳本和控制檯我收到消息如下提到:

<project name="sample"> 
<property name="name" value="sample"/> 
<path id="catalina-ant-classpath"> 
<fileset dir="C:\Users\vivsharm\Downloads\apache-tomcat-7.0.64-windows-x64\apache-tomcat-7.0.64\lib"> 
<include name="catalina-ant.jar"/> 
</fileset> 
</path> 
<taskdef name="start" classname="org.apache.catalina.ant.StartTask"> 
<classpath refid="catalina-ant-classpath"/> 
</taskdef> 

<taskdef name="stop" classname="org.apache.catalina.ant.StopTask"> 
<classpath refid="catalina-ant-classpath"/> 
</taskdef> 

<target name="start" description="Start Tomcat application"> 
<start url="http://localhost:8080/" 
username="uname" 
password="pwd"/> 
</target> 
<target name="stop" description="Stop Tomcat application"> 
<stop url="http://localhost:8080/" 
username="uname" 
password="pwd"/> 
</target> 
</project> 

,我收到錯誤消息如下:

C:\StartAndStopTomcat>ant start 
Buildfile: C:\StartAndStopTomcat\build.xml 

start: 

BUILD FAILED 
C:\StartAndStopTomcat\build.xml:19: Must specify 'path' attribute 

Total time: 0 seconds 

C:\StartAndStopTomcat>ant stop 
Buildfile: C:\StartAndStopTomcat\build.xml 

stop: 

BUILD FAILED 
C:\StartAndStopTomcat\build.xml:24: Must specify 'path' attribute 

Total time: 0 seconds 

    enter code here 

C:\StartAndStopTomcat> 

回答

0

我們構建腳本是很老,所以可以有更好的辦法做到這一點,但我們用

<property name="tomcat.bin.dir" location="${tomcat.catalina_home}/bin" /> 
<property name="tomcat.startup.file" location="${tomcat.bin.dir}/startup${os.script_extension}" /> 
... 
<target name="tom-start" description="start tomcat server"> 
    <echo message="starting ${tomcat.catalina_base}" /> 
    <exec executable="${os.command_interpreter}"> 
     <arg line="${os.command_interpreter.mandatory_argument}" /> 
     <arg line="${tomcat.startup.file}" /> 
     <env key="CATALINA_BASE" value="${tomcat.catalina_base}" /> 
     <env key="JAVA_HOME" value="${javac.jdk.dir}" /> 
     <env key="JRE_HOME" value="${javac.jdk.dir}" /> 
     <env key="JAVA_OPTS" value="${JAVA_OPTS}" /> 
    </exec> 
</target> 
<target name="tom-shut" description="stop tomcat server (remember that it might not shut down immediately)"> 
    <echo message="shutting down ${tomcat.catalina_base}" /> 
    <exec executable="${os.command_interpreter}"> 
     <arg line="${os.command_interpreter.mandatory_argument}" /> 
     <arg line="${tomcat.shutdown.file}" /> 
     <env key="CATALINA_BASE" value="${tomcat.catalina_base}" /> 
     <env key="JAVA_HOME" value="${javac.jdk.dir}" /> 
     <env key="JRE_HOME" value="${javac.jdk.dir}" /> 
    </exec> 
</target> 

os.command_interpreter是linux機器上的/bin/bash,或者是Windows機器的C:\\Windows\\System32\\cmd.exe。當然你也需要預先設置tomcat.catalina_home等屬性。

相關問題