English 中文(简体)
我如何在Eclipse中自动化(脚本)创建war文件?
原标题:
  • 时间:2008-11-16 14:05:24
  •  标签:

点击五个按钮,即可使eclipse创建可部署的war文件,我想可能有一些eclipse命令行选项可以完成同样的事情,这样我就可以将其写入脚本,但我没有找到。

最佳回答

使用Ant war任务,设置相关的构建文件,并可以单击“外部工具”按钮执行它。

问题回答

您还可以为您的Web项目设置Maven构建。从命令行键入“ mvn package ”将为您构建项目。

有关Maven和Eclipse的集成,请参见m2EclipseMaven Eclipse Plugin

我不能对WAR包装本身发表任何言论,抱歉。

But as I wrote in How do I automatically export a WAR after Java build in Eclipse? : If you can describe the WAR packaging with an Ant script, you can have that Ant script being executed automatically after each change to your project. Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project. You can even specify in the settings of the builder, if it shall only react on changes to specific files and so on.

蚂蚁构建工具就好像是一把瑞士军刀,可用于自动化项目构建的任何操作,而无需使用像Maven这样的大型工具。

这个Ant脚本应该适用于项目的标准动态Web项目结构:

创建Ant build.xml,替换开始的两个属性:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Deploy From Eclipse to JBoss" basedir="." default="deploy">

  <!-- This replace with yours project name and JBoss location: -->
  <property name="warfile" value="MyProject"/>
  <property name="deploy" value="/home/honza/jboss-as-7.1.1.Final/standalone/deployments"/>

  <target name="create">
    <war destfile="${warfile}.war" webxml="WebContent/WEB-INF/web.xml" update="true">
      <classes dir="buildclasses"/>
      <fileset dir="WebContent">
        <exclude name="WEB-INF/web.xml"/>
      </fileset>
    </war>
  </target>
  <target name="copy">
    <copy todir="${deploy}" overwrite="true">
      <fileset dir=".">
        <include name="${warfile}.war"/>
      </fileset>
    </copy>
  </target>
  <target name="clear">
    <delete includeemptydirs="true">
      <fileset dir="${deploy}" defaultexcludes="false">
        <include name="${warfile}.*/**" />
      </fileset>
    </delete>
  </target>
  <target name="deploy">
    <antcall target="create"/>
    <antcall target="clear"/>
    <antcall target="copy"/>
  </target>
</project>

现在应该使用“ant”命令进行WAR包的创建,并将它们复制到JBoss。JBoss会自动部署在部署目录中找到的WAR包。

为了在构建后执行自动运行(项目 - 构建),请在此处添加以下Buildfile:

MyProject - Properties - New - Ant builder




相关问题
热门标签