• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to automate deployment of war in Tomcat through Ant

 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
My intention is to use Ant to automate build, deployment,starting & stopping server of applications.
Now I'm able to build the application through Ant.
My build.xml is inside my application

JdbcMYSQLservlet/build.xml
JdbcMYSQLservlet/WEB-INF


This is my build.xml


While running


1)Now I want to automate the deployment of this war file i.e. JDBCMySQLServlet.war into webapps folder.

2) Also when we're deploying this war file, the server has to be shutdown & restarted.
How this can be done?
Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any replies?
Regards
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your project is in Tomcat's webapps directory? Not a good idea. I recommend that you place your project elsewhere.

It would appear that your Ant script is creating the file E:\apache-tomcat-5.5.27\webapps\JDBCServlet\WEB-INF\jar\JDBCMySQLServlet.war. As far as I know there is no way that Tomcat will ever recognize that file because it is not at the correct location. It would have to be located at E:\apache-tomcat-5.5.27\webapps\JDBCMySQLServlet.war.

Personally, after moving my project elsewhere, I would gather all the contents necessary to build the WAR file in one location. Then I would copy the contents of that directory to the E:\apache-tomcat-5.5.27\webapps\JDBCServlet directory. Tomcat should pick up the changes to your JSPs and static content. For changes to classes, such as servlets, you will probably have to restart Tomcat.

You can use the Ant "exec" task to run the shutdown and startup scripts for Tomcat in order to restart Tomcat.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Peter,
First of all thanks for your valuable input in this challenge.
I've been waiting for this for quite some time from now.

It would have to be located at E:\apache-tomcat-5.5.27\webapps\JDBCMySQLServlet.war.


Correct & now I've changed.

1) But when I'm cleaning that war file I tried to use the delete dir attribute which is not deleting the war file, eventhough the build is successful

<target name="clean">
<echo message="In clean "/>
<delete dir="${classes.dir}"/>
<delete dir="E:\apache-tomcat-5.5.27\webapps\JDBCMySQLServlet.war"/>
<echo message="Clean successfully over"/>
</target>


Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For changes to classes, such as servlets, you will probably have to restart Tomcat.

Are you sure, we have to start tomcat can't we do hot deployment into the server.
Hot deployment
So what I thought was
1) We need to create a modified war file
2) We need to run the TCD's build.xml to deploy the modified war file into server, while the server is running.
Is this correct?
I tried out the same & even created a build.xml for TCD(TomcatClientDeployer)
& tried running that but somehow it was not working fine.

3) In Java, whatever is inside jre/lib/ext folder the runtime environment identifies it, likewise is there any arrangement of that sort in Tomcat server so that we can put the modified war file there so that the server recognises it.

4) One more doubt is in some real-time applications when they want to change the application & deploy it, I've heard that they are following this approach of hot deployment so that the existing users don't suffer from the server shutdown.

Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To delete the file , I used the following attribute in my build.xml

It's working now!
Regards.
 
Edwin Stephens
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ramya,

For stopping, starting, undeploying, and deploying to Tomcat via Ant, you might want to consider trying out the following Ant tasks in the catalina-ant.jar file:


A tutorial showing how to build a war file and deploy to Tomcat using the Ant DeployTask can be found here:
http://www.avajava.com/tutorials/lessons/how-do-i-deploy-to-tomcat-using-ant.html

Hope that helps,
Edwin
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly Edwin I'll certainly go through that link & I do hope it would be very useful for me.
Anyhow thanks Edwin for sharing your ideas & time for me.
Regards
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do we need to stop the server for this?
I want to " deploy on the fly" i.e. when the server is running I need to deploy to it.
Regards.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to use the Ant tasks? In that case no.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to use the Ant tasks? In that case no

Dear Martin need some clarifications as I don't understand your post .

Ideal scenario:
I want to use Ant to deploy the new war file to the Tomcat server without shutting it down.
Is it possible?

If not,
Is it possible to use Ant to shutdown the server & start the server to deploy
especially can we use that ant exec command for this.
In that case if I make simple changes in my class file, then use of ant is sufficient.

Regards.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the post from Edwin above, it lists the Ant tasks you can use to start, stop, deploy, undeploy from Tomcat.

In theory you can just use the undeploy/deploy tasks while Tomcat is still running. However if you're paranoid like me you can use the stop and start tasks before/after you deploy.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood & thanks martin for your patient reply!
Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic