我需要使用Ant脚本启动和停止Tomcat服务器,但是我在Stack Overflow上找到了一个脚本,但是当我使用它时,它给出了下面提到的错误。
脚本和我得到的控制台上的消息如下所述:
<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 :(得分: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
和其他属性。