本文介绍了Apache Ant的部署如何.war文件到Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache Ant的1.8到Web应用程序部署到本地Tomcat服务器,当我在命令行中运行蚂蚁部署build.xml文件(如下图)产生预期的效果。

I'm using Apache Ant 1.8 to deploy a web application into a local Tomcat server, and the build.xml file (below) produces the desired effect when I run 'ant deploy' at the command line.

我的问题是,我注意到,.war文件被放置在我期待它(deploy.dir是我的主目录的build.properties文件中定义),而且还出人意料地解压缩的.war和提取的背景本身放到同一个目录。凡在下面的build.xml文件是配置?

My question is, I noticed that the .war file gets placed where I expect it to (deploy.dir is defined in my home directory's build.properties file), but it also unexpectedly unpacked the .war and extracted the context itself into that same directory. Where in the below build.xml file is that configured?

  <target name='init'>
    <property file='${user.home}/build.properties'/>
    <property name='app.name' value='${ant.project.name}'/>
    <property name='src.dir' location='src'/>
    <property name='lib.dir' location='lib'/>
    <property name='build.dir' location='build'/>
    <property name='classes.dir' location='${build.dir}/classes'/>
    <property name='dist.dir' location='${build.dir}/dist'/>
  </target>

  <target name='initdirs' depends='init'>
    <mkdir dir='${classes.dir}'/>
    <mkdir dir='${dist.dir}'/>
  </target>

  <target name='compile' depends='initdirs'>
    <javac srcdir='${src.dir}/java' destdir='${classes.dir}'>
      <!--
      <classpath>
        <fileset dir='${lib.dir}/development' includes='javaee.jar'/>
        <fileset dir='${lib.dir}/production' includes='jr.jar'/>
      </classpath>
      -->
    </javac>
  </target>

  <target name='war' depends='compile'>
    <war destFile='${dist.dir}/${app.name}.war' webxml='${src.dir}/web/WEB-INF/web.xml'>
      <classes dir='${classes.dir}'/>
      <!--
      <zipfileset dir='${lib.dir}/production' includes='jr.jar' prefix='WEB-INF/lib' />
      -->
      <fileset dir='${src.dir}/web' excludes='WEB-INF/web.xml' />
    </war>
  </target>

  <target name='build' depends='war' description='compile and create the war' />

  <target name='clean' depends='init' description='Use for a clean build'>
    <delete dir='${build.dir}' />
  </target>

  <target name='ffbuild' depends='clean, build' description='clean and create the war'/>

  <target name='deploy' depends='initdirs' description='copy the war file to the app server'>
    <delete verbose='true' dir='${deploy.dir}/${app.name}'/>
    <fail unless='deploy.dir' message='build.properties must exist in your home directory and define deploy.dir' />
    <copy todir='${deploy.dir}' file='${dist.dir}/${app.name}.war'/>
  </target>

推荐答案

Tomcat的具有在您将任何战争的文件会自动解压缩并部署了一个自动部署文件夹。你的Ant文件是通过调用在tomcat-Manager Web应用程序的特殊URL(这是ppackaged到Tomcat $ P $)复制war文件到这个目录。

Tomcat has an autodeploy folder in which any war file that you place will be automatically unpacked and deployed. Your ant file is simply copying the war file into this directory by calling a special URL in the tomcat-manager web application (which is prepackaged into the tomcat).

这一切这一点是由tomcat的核心自动处理,只是如果你复制war文件到手动webapps目录。

From this point on everything is handled by the tomcat core automatically, just if you copied the war file into the webapps directory manually.

您可以有蚂蚁做很多与Tomcat的一些特定的Ant任务。特别是如果Tomcat服务器不在本地机器上。 有关详细信息,请参阅的这个环节。

You can have ant do a lot more with some specific ant tasks for tomcat. Especially if the Tomcat server is not on the local machine. See this link for details.

这篇关于Apache Ant的部署如何.war文件到Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 23:52