aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to automate deployment of war in Tomcat through Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to automate deployment of war in Tomcat through Ant" Watch "How to automate deployment of war in Tomcat through Ant" New topic
Author

How to automate deployment of war in Tomcat through Ant

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338
Any replies?
Regards
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

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.


JBoss In Action
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338

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

Joined: Oct 06, 2008
Posts: 338
To delete the file , I used the following attribute in my build.xml

It's working now!
Regards.
Edwin Stephens
Greenhorn

Joined: Dec 30, 2008
Posts: 15
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

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

Do you mean to use the Ant tasks? In that case no.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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

Joined: Oct 06, 2008
Posts: 338
Understood & thanks martin for your patient reply!
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to automate deployment of war in Tomcat through Ant
 
Similar Threads
Ant Build Failing -- Need a way to pick jar file during run time.
Apache Ant add property file and policy file
Class files generated in web-inf directory as well as in base directory
Build problem when including third party jars in classpath using ant
How to excute the build.xml for the ant script