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

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文件定义的命名空间)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值