ant tomcat 启动 关闭 注册成windows服务
tomcat注册成windows服务:
打开cmd命令行,进入tomcat目标下的bin目录里,执行service.bat install tomcat_juziku(服务名)
?
如果想删除windows服务,可以进入cmd命令行,执行sc delete tomcat_juziku(其中,tomcat_juziku为服务名,如果服务名中间有空格,就需要前后加引号)
?
?
--------------------------------
问题: 自己写ant的时候build完war后想部署到tomcat上,然后启动tomcat,在启动前会先运行shutdown尝试关闭tomcat,并且删除掉之前部署的war和相关目录,结果运行shutdown之后马上尝试删除的时候,说是有些资源被使用,无法删除,应该是shutdown执行的关闭tomcat没有完全执行完,就开始执行删除,导致资源被使用中,在网上找了些相关的处理办法,记录如下:
?
1.
==========================================
ant 启动 tomcat
<target name="tomcat.start">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>
</target>
<target name="tomcat.stop">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<arg line="stop"/>
</java>
</target>
<target name="tomcat.debug">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true">
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
<jvmarg value="-Xdebug"/>
<jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"/>
</java>
</target>
?
?
2、
=======================================================
?
?
?
?
?
3、
=======================================================
启动注意tomcat.home是你的tomcat的安装路径
?
?
?
?关闭
?
?
?
总结:
自己试了下,用的第3种,其实他没有彻底解决我的问题,就是多了一个wait的时间,这个时间也是个估计值
?
?
?
?
?
?
?
?
liunx 下的? ant tomcat
===================================================================
最近公司项目上线了,这一段时间我频繁地按照Release Guide做重复性操作,不胜其烦。今天刚好有空,就用ant加Linux的sh文件做了一个自动Release的脚本,哈哈,以后方便了,一条命令就可以全部搞定。
??? 首先把ant解压到路径/opt/app下,然后用vi编辑/etc/profile文件,加入以下几个语句:
??? export ANT_HOME=/opt/app/apache-ant-1.7.0
??? export JAVA_HOME=/opt/app/jdk1.5.0_16
??? export PATH=$PATH:$JAVA_HOME/bin:$ANT_HOME/bin
??? 按Esc后同时按shift跟:键,接着输入命令wq退出vi。现在我们可以写ant脚本跟sh文件了/*? release.sh? */
cd /opt/app/apache-tomcat-5.5.26/bin
./shutdown.sh
killall -9 java???????? //因为有时候shutdown不能完全关闭tomcat,所以就用这条命令把java线程全部kill掉kill -TERM `ps -ef | grep 5.5.26 | grep -v grep | awk '{print $2}'`? //或者仅仅kill掉tomcat-5.5.26的线程
rm -rf /opt/app/apache-tomcat-5.5.26/work/Catalina/localhost
cd /opt/app/my
ant all
cd /opt/app/my_1.0_dynamic
unzip? my_dynamic.war
mv /opt/app/my/trunk/my.xml /opt/app/apache-tomcat-5.5.26/conf/Catalina/localhost/???? //这个文件指定Context
cd /opt/app/apache-tomcat-5.5.26/bin
./startup.sh/*? my.xml? */
<?xml version="1.0" encoding="UTF-8"?><Context docBase="/opt/app/my_1.0_dynamic" crossContext="true" >
</Context>/*? build.properties? */
# -----------------------------------------
# build.properties
# This file is referenced by the build.xml file.
# -----------------------------------------svnant.version=1.0.0
# -----------------------------------------
# all jar needed
# -----------------------------------------
svnlib.dir=trunk/lib/svnant
svnant.jar=${svnlib.dir}/svnant.jar
svnClientAdapter.jar=${svnlib.dir}/svnClientAdapter.jar
svnjavahl.jar=${svnlib.dir}/svnjavahl.jarsvnant.latest.url=http://192.168.1.1/svn/projects/my/coding/trunk/
svnant.repository.user=your username
svnant.repository.passwd=your passworddev.apache.DocumentRoot=/opt/app/httpd-2.2.9-ssl-rewrite/htdocs
/*? build.xml? */
<?xml version="1.0"?><project name="myProject" basedir="." default="usage">
??? <!--? all properties are in build.properties -->
??? <property file="build.properties" />??? <property name="name" value="${ant.project.name}"/>
??? <property name="src.dir" value="trunk/src"/>
??? <property name="src.webapp" value="trunk/web"/>
??? <property name="lib.dir" value="trunk/lib"/>
??? <property name="static.dir" value="trunk/static"/>
???
??? <property name="build.dir" value="trunk/build"/>
??? <property name="build.webapp" value="${build.dir}/webapp"/>
??? <property name="build.classes" value="${build.webapp}/WEB-INF/classes"/>??? <property name="dist.dir" value="/opt/app/my_1.0_dynamic"/>
??? <!-- path to the svnant libraries. -->
??? <path id="svnant.classpath">
??????? <pathelement location="${svnjavahl.jar}" />
??????? <pathelement location="${svnant.jar}" />
??????? <pathelement location="${svnClientAdapter.jar}" />
??? </path>
??? <taskdef resource="svntask.properties" classpathref="svnant.classpath"/>???
???
??? <!-- another way is to put all lib to ant_home/lib and just uncomment the following line. -->
??? <!-- <taskdef resource="svntask.properties"/>-->
?
? <target name="checkout">
??? <svn username="${svnant.repository.user}" password="${svnant.repository.passwd}">
????? <checkout url="${svnant.latest.url}" revision="HEAD" destPath="trunk" />
??? </svn>
? </target>??? <path id="master-classpath">
??????? <fileset dir="${lib.dir}">
??????????? <include name="*.jar"/>
??????? </fileset>
??????? <fileset dir="${lib.dir}/test">
??????????? <include name="*.jar"/>
??????? </fileset>
??????? <fileset dir="${lib.dir}/servlet">
??????????? <include name="*.jar"/>
??????? </fileset>
??? </path>??? <target name="usage">
??????? <echo message=""/>
??????? <echo message="my build"/>
??????? <echo message="------------------------------------------------------"/>
??????? <echo message=""/>
??????? <echo message="Available targets are:"/>
??????? <echo message=""/>
??????? <echo message="clean??? --> Clean output dirs"/>
??????? <echo message="checkout --> Check out latest source from svn server"/>
??????? <echo message="build??? --> Compile main Java sources and copy libraries"/>
??????? <echo message="war????? --> Build a war file"/>
??????? <echo message="all????? --> Clean, checkout,build, war, tests"/>
??????? <echo message=""/>
??? </target>??? <target name="init" description="Clean output dirs (.classes and .testclasses)">
??????? <mkdir dir="${build.dir}"/>
??????? <mkdir dir="${build.webapp}"/>
??????? <mkdir dir="${build.webapp}/WEB-INF"/>
??????? <mkdir dir="${build.webapp}/WEB-INF/lib"/>
??????? <mkdir dir="${build.classes}"/>
??? </target>
???
??? <target name="clean" description="Clean output dirs (.classes and .testclasses)">
??????? <delete dir="${build.dir}"/>
??????? <delete dir="${dist.dir}"/>
??????? <delete>
??????????? <fileset dir="${src.webapp}/WEB-INF/lib" includes="**/*.jar"/>
??????? </delete>
??????? <delete dir="${src.webapp}/WEB-INF/classes/au"/>
??? </target>??? <target name="build" depends="init" description="Compile main source tree java files into class files, generate jar files">
??????? <javac destdir="${build.classes}" source="1.5" target="1.5" debug="true"
?????????????? deprecation="false" optimize="false" failonerror="true" encoding="utf-8">
??????????? <src path="${src.dir}"/>
??????? <classpath refid="master-classpath"/>
??????? </javac>?
??? </target>??? <target name="webapp" depends="init, build">
??????? <copy todir="${build.webapp}">
??????????? <fileset dir="${src.webapp}"/>
??????? </copy>
??????? <copy todir="${build.webapp}/WEB-INF/lib">
??????????? <fileset dir="${lib.dir}">
??????????????? <exclude name="**/servlet*"/>
??????????????? <exclude name="**/servlet/*"/>
??????????????? <exclude name="**/test*"/>
??????????????? <exclude name="**/test/*.jar"/>
??????????????? <exclude name="**/svnant/*.jar"/>
??????????????? <exclude name="**/svnant*"/>
??????????? </fileset>
??????? </copy>
??????? <copy todir="${build.webapp}/WEB-INF/classes">
??????????? <fileset dir="${src.dir}">
??????????????? <include name="**/resources/*"/>
??????????? </fileset>
??????? </copy>
??????? <copy todir="${build.webapp}/WEB-INF/classes">
??????????? <fileset dir="${src.dir}">
??????????????? <include name="**/*validation.xml"/>
??????????? </fileset>
??????? </copy>
??????? <copy todir="${dev.apache.DocumentRoot}">
??????????? <fileset dir="${static.dir}">
??????????? </fileset>
??????? </copy>
??? </target>??? <target name="war" depends="init, build, webapp">
??????? <jar jarfile="${build.webapp}/WEB-INF/lib/my.jar" basedir="${build.webapp}/WEB-INF/classes" >
??????? <include name="**/au/**"/>
??????? <include name="**/com/**"/>
??????? </jar>
??????? <jar jarfile="${build.dir}/my_dynamic.war" basedir="${build.webapp}" >
??????????????? <exclude name="**/jai_*.jar"/>
??????? <exclude name="**/classes/au/**"/>
??????? <exclude name="**/classes/com/**"/>
??????? </jar>
? </target>??? <target name="dist" depends="init, build, webapp, war">
?????????? <mkdir dir="${dist.dir}"/>
??????? <copy file="${build.dir}/my_dynamic.war" todir="${dist.dir}"/>
???? </target>
??? <target name="all" depends="clean,checkout,dist" description="Clean,checkout,build,warfile,dist"/>
???
</project>?
?
?
?
?
1 楼 spp_1987 2010-06-30 好羡慕啊,我现在用Ant 就是不厌其烦的重启和关掉Tomcat才能更新的部署项目.
我用的环境是windows啊,看了楼主的哪些方法,但是还是不怎么明白该怎么去配置. 2 楼 lich0079 2010-06-30 window下把tomcat安装成服务 是可以准确的在tomcat关闭完全后,然后重新部署,然后启动的,我没试过,以前有同事是这么做成功了的 3 楼 debbykindom 2010-10-19 My conclusion is that your problem still not yet been solved, mess.