1
votes

I want use Ant to automate build, deployment,starting & stopping server of applications. I'm able to build the application through Ant and copied the war file into the Tomcat webapps directory.

On the Internet, I found this article which contains more code to start and stop Tomcat. Since I can successfully deploy without those, I was wondering why they are there.

The code for my build.xml is below.

 <?xml version="1.0"?>
    <project name="Test" default="build-war">
        <property file="build.properties"></property>
        <target name="build-war" depends="clean">
                <war destfile="Test.war" webxml="${web.dir}/WEB-INF/web.xml" >
                    <fileset dir="${web.dir}">
                        <include name="**/*.*"/>
                    </fileset>
                <classes dir="${build.dir}/classes"></classes>
                </war>
                <copy todir="${deploy.path}" preservelastmodified="true">
                        <fileset

 dir=".">
                        <include name="*.war"/>
                    </fileset>
            </copy>
        </target>
    <target name="clean" description="Clean Test war directories">
        <delete>
            <fileset dir="${deploy.path}">
                <include name="Test.war"/>
            </fileset>
        </delete>
    </target>
</project>
1
The code looks correct. What is your problem? Please include all relevant information that you have in your question; we can't see your desktop, read your mind or your hard disk.Aaron Digulla
the problem is that when I am looking the below article tutorialspoint.com/ant/ant_deploying_applications.htmvishal
This sentence again doesn't contain much useful information.Aaron Digulla
the above article contains some ant task (start,stop etc) but I am able to deploy the file without using these then what is the use of it and why we use those tasksvishal
I've edited your question. Is this what you want to know?Aaron Digulla

1 Answers

0
votes

There is no reliable way to (re)deploy an application to a web server. The reasons why an app might fail to deploy are numerous (thread leak, shutdown hooks, accessing parent classloaders) but in the end, there is no reliable way to tell whether a (complex) application could be deployed successfully.

This means that most developers have learned to use this cycle:

  1. Deploy. Tomcat should automatically notice the new files and restart.
  2. If something is odd, try to reload (ReloadTask). This tells Tomcat "no matter what you believe, the app has changed! Start it again!"
  3. If the app still fails, stop and start Tomcat again.
  4. If that fails, stop tomcat, delete all files, deploy again and after deployment, start Tomcat again.
  5. If that fails, delete Tomcat and all files, reinstall, ...

Yes, I once had a script which could do every of the steps above. :-)

In the end, I gave up on deployment. My current solution is to write a Java application which creates an embedded Tomcat or Jetty server, configures it and starts the app. I have just a single classpath. No file copying, deployment or any such nonsense necessary. That way, I just have a single process, only a single web app in the container and I have all logs in one place.