The following Ant Script can be used to build your web application and deploy it in the remote server. it is required to change the value of the properties based on their actual paths available in your server and development environment. the following Ant Script should be copied to the build.xml file that is available inside the root of your java web project directory. (if there is no build.xml file, you can just create it and copy the below codes to there )
<project name="myproject" default="all">
<target name="init">
<property name="server_home" value="C:/Program Files/Apache Software Foundation/Tomcat 6.0"/>
<property name="server_deploy" value="${server_home}/webapps"/>
<property name="servlet_jar" value="${server_home}/lib/javax.servlet.jar"/>
<property name="outdir" value="./output"/>
<property name="classes" value="${outdir}/webclasses"/>
<property name="lib" value="${outdir}/lib"/>
<property name="project_name" value="jdbc"/>
</target>
<target name="prepare" depends="init">
<mkdir dir="${outdir}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${lib}"/>
</target>
<target name="compile" depends="prepare">
<echo>${servlet_jar}</echo>
<javac srcdir="./src" destdir="${classes}">
<classpath>
<pathelement location="${servlet_jar}"/>
</classpath>
</javac>
</target>
<target name="package" depends="compile">
<jar destfile="${lib}/lib.jar" basedir="${classes}" includes="**/data/*.*"/>
<war destfile="${outdir}/${project_name}.war" webxml="./WebContent/WEB-INF/web.xml">
<fileset dir="./WebContent"/>
<classes dir="${classes}">
</classes>
<lib dir="${lib}"/>
</war>
</target>
<target name="deploy" depends="package">
<copy file="${outdir}/${project_name}.war" todir="${server_deploy}"/>
</target>
<target name="clean" depends="init">
<delete dir="${outdir}"/>
<delete file="${server_deploy}/${project_name}.war"/>
</target>
<target name="all" depends="clean, deploy">
</target>
</project>
<project name="myproject" default="all">
<target name="init">
<property name="server_home" value="C:/Program Files/Apache Software Foundation/Tomcat 6.0"/>
<property name="server_deploy" value="${server_home}/webapps"/>
<property name="servlet_jar" value="${server_home}/lib/javax.servlet.jar"/>
<property name="outdir" value="./output"/>
<property name="classes" value="${outdir}/webclasses"/>
<property name="lib" value="${outdir}/lib"/>
<property name="project_name" value="jdbc"/>
</target>
<target name="prepare" depends="init">
<mkdir dir="${outdir}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${lib}"/>
</target>
<target name="compile" depends="prepare">
<echo>${servlet_jar}</echo>
<javac srcdir="./src" destdir="${classes}">
<classpath>
<pathelement location="${servlet_jar}"/>
</classpath>
</javac>
</target>
<target name="package" depends="compile">
<jar destfile="${lib}/lib.jar" basedir="${classes}" includes="**/data/*.*"/>
<war destfile="${outdir}/${project_name}.war" webxml="./WebContent/WEB-INF/web.xml">
<fileset dir="./WebContent"/>
<classes dir="${classes}">
</classes>
<lib dir="${lib}"/>
</war>
</target>
<target name="deploy" depends="package">
<copy file="${outdir}/${project_name}.war" todir="${server_deploy}"/>
</target>
<target name="clean" depends="init">
<delete dir="${outdir}"/>
<delete file="${server_deploy}/${project_name}.war"/>
</target>
<target name="all" depends="clean, deploy">
</target>
</project>
No comments:
Post a Comment