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

问题描述

我正在使用 Apache Ant 1.8 将 Web 应用程序部署到本地 Tomcat 服务器,当我在命令行运行ant deploy"时,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 有一个 autodeploy 文件夹,您放置在其中的任何 war 文件都将自动解压和部署.您的 ant 文件只是通过调用 tomcat-manager Web 应用程序(已预先打包到 tomcat 中)中的特殊 URL 将 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.

您可以让 ant 为 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