2008-11-16 65 views
6

它的5个按钮点击获得eclipse为我的eclipse项目创建一个可部署的战争文件,我认为可能有一些eclipse命令行选项可以做同样的事情,所以我可以将它写入脚本,但我不是看到它。如何自动化(脚本)在eclipse中创建战争文件?

+0

嗨@stu请你有Ant脚本,让我这样做呢? – mounaim 2015-05-23 21:23:28

+1

看看这里。 http://www.dzone.com/tutorials/java/ant/ant-sample-build-file-war-1.html查看关于target =“war”的部分 – stu 2015-05-25 20:42:35

回答

3

使用Ant war task,设置相关的构建文件,你可以点击“外部工具”按钮来执行它。

2

你也可以为你的web项目设置一个Maven构建。然后从命令行键入mvn包将为您构建项目。

对于Maven和Eclipse之间的集成,请参阅m2EclipseMaven Eclipse Plugin

1

我无法对WAR包装本身说些什么,对不起。

但正如我在 How do I automatically export a WAR after Java build in Eclipse?写道:如果你可以描述了一个Ant脚本的WAR包装,你可以有Ant脚本被每次更改项目后自动执行。使用Project-> Properties-> Builders-> Add-> Ant Builder。为该构建器提供您自定义的Ant脚本,并在您的项目的“常规”构建器之后自动执行该脚本。 您甚至可以在构建器的设置中指定它是否只对特定文件的更改等作出反应。

蚂蚁生成器是一种瑞士军刀,用于任何想要在项目构建中自动化的任何内容,而无需使用像maven这样的大工具。

0

这Ant脚本应为项目的标准动态Web项目结构工作:

<?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="build\classes"/> 
     <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> 

现在应该命令 “蚁族”:

与begining两个属性的替代创建的Ant build.xml做WAR创建并将它们复制到JBoss。 JBoss会自动部署在部署目录中找到的战争。

对于自动运行生成后(项目 - 建造)在这里添加此构建文件:

MyProject - Properties - New - Ant builder