您的位置:首页 > 运维架构 > Tomcat

Ant 对struts2+Ibatis+Spring3的项目编译,打包,发布到Tomcat

2012-04-14 16:11 537 查看
1.确定目录结构,如下:



2.编写build.xml文件,内容如下:

<?xml version="1.0" encoding="gb2312" ?>

<project name="projectStudy" basedir=".">

<!--war任务-->

<!--将整合的struts2+Ibatis+Spring.3.0打包成war-->

<property name ="build" value ="build"/>

<property name ="classes" value ="build/classes"/>

<property name ="lib" value ="WebRoot/WEB-INF/lib"/>

<!--Tomcat安装目录-->

<property name ="tomcat.home" value ="D:\apache-tomcat-6.0.18"/>

<!--定义编译javac时,所依赖的jar包-->

<path id="jarlib">

<fileset dir="WebRoot\WEB-INF\lib">

<include name="*.jar"/>

</fileset>

</path>

<!--删除build目录-->

<target name ="sisClean">

<delete dir ="${build}"/>

</target>

<!--编译前,先删除build目录,每次编译都重新创建build目录-->

<target name="sisCompile" depends ="sisClean">

<mkdir dir ="${classes}"/>

<javac srcdir ="src" destdir ="${classes}" encoding="gbk">

<classpath refid="jarlib"></classpath>

</javac>

<!--将src下的配置文件也一起复制到classes目录下-->

<copy todir="${classes}">

<fileset dir="src" includes="log4j.properties,oscache.properties,struts.properties,struts.xml" />

</copy>

</target>

<target name ="warTarget" depends ="sisCompile" >

<war destfile ="${build}/sis.war" webxml="WebRoot\WEB-INF\web.xml">

<fileset dir ="WebRoot"/>

<!-- 拷贝lib 目录下的jar 包-->

<lib dir ="${lib}"/>

<!-- 拷贝build/classes 下的class 文件-->

<classes dir="${classes}"/>

</war>

</target>

<!--将打包好的war,复制到tomcat的webapps的目录下,即发布-->

<target name="tomcat.deploy" description="部署到tomcat">

<copy todir="${tomcat.home}/webapps" overwrite="true">

<fileset dir="${build}" includes="sis.war" />

</copy>

</target>

<!--启动Tomcat的任务-->

<target name="tomcat.start">

<java jar="${tomcat.home}\bin\bootstrap.jar" fork="true">

<jvmarg value="-Dcatalina.home=${tomcat.home}" />

<jvmarg value="-Dsys.run.environment=SPS" />

<jvmarg value="-Xdebug" />

</java>

</target>

<!--关闭Tomcat的任务-->

<target name="tomcat.stop">

<java jar="${tomcat.home}\bin\bootstrap.jar" fork="true">

<jvmarg value="-Dcatalina.home=${tomcat.home}" />

<arg line="stop" />

</java>

</target>

</project>

3.dos控制台,依次运行

ant warTart

ant tomcat.deploy

ant tomcat.start

4.浏览器运行:http://localhost:8989/sis/sis/userAc!userList.action(第一个sis是项目发布的名字,第二个sis是strusts.xml文件定义的命名空间)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: