开发者

Tomcat integrated with Eclipse

I have configured a Tomcat instance within the Eclipse workspace for debugging my web application.

Is there any way to configure or control the activities 开发者_C百科of the Tomcat instance, outside the Eclipse environment or through any (script or code)?

[Note:- I am trying to create an ant script, to combine the activities like stop the server, copy the source code from version control system, compile the updated source, redeploy it in the eclipse integrated server path and restart the server. Your inputs will help me a lot!!]

Thanks in advance.!!!

Tomcat integrated with Eclipse


Ant can perform all these actions for you. As far as the startup/stopping of the server is concerned, Tomcat includes classes to manipulate these actions from ant found in the {YOUR_TOMCAT_HOME}/server/lib/catalina-ant.jar.

The ant-tasks should look like this (excert from this link):

Suppose name of your application name is newapp then in your build.xml include following.

<property name="name" value="newapp"/>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/>
</classpath> 
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
<classpath>
<path location="${appserver.home}/server/lib/catalina-ant.jar"/> 
</classpath>
</taskdef>
<target name="start" description="Start Tomcat application">
<start url="${tomcat.manager.url}"
username="${tomcat.manager.username}"
password="${tomcat.manager.password }"
path="/${name}"/>
</target>

<target name="stop" description="Stop Tomcat application">
<stop url="${tomcat.manager.url}"
username="${ tomcat.manager.username}"
password="${tomcat.manager.password}"
path="/${name}"/>
</target>

And make a file build.properties which contains variables used by build.xml

# Ant properties for building the springapp
appserver.home=${user.home}/jakarta-tomcat-5.0.28
deploy.path=${appserver.home}/webapps
tomcat.manager.url=http://localhost:8080/manager
tomcat.manager.username=admin 
tomcat.manager.password=tomcat


You do it with an Ant-Script. Just write a script that, compiles your webapp, then package the whole application with the WAR-Target. Stop the tomcat via the Exec-Target, copy the war-file and start the tomcat again with the Exec-Target.

If you've installed your tomcat as a service you can use the windows command net stop "tomcatServiceName" to stop your tomcat. e.g.

<target name="stop-tomcat6">
    <exec executable="cmd">
        <arg line='/c net stop "Apache Tomcat"'/>
    </exec>
</target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜