简体   繁体   English

Eclipse:按顺序自动运行Ant脚本

[英]Eclipse: Automatically run Ant scripts in sequent order

I am using Eclipse's Ant view to run my build files. 我正在使用Eclipse的Ant视图运行我的构建文件。 I have to run a couple of files in a specific order and I wonder whether there is any possibility to automate this (I'm sure there is...). 我必须按照特定的顺序运行几个文件,并且我想知道是否有可能使它自动化(我敢肯定有...)。 However, they need to run subsequently, ie script two may not start until script one finished successfully. 但是,它们需要随后运行,即脚本二可能要等到脚本一成功完成后才能启动。 Most of my Ant scripts trigger Maven commands. 我的大多数Ant脚本都会触发Maven命令。

Is there any Eclipse plugin or feature that can assist me in running my Ant files automatically? 是否有任何Eclipse插件或功能可以帮助我自动运行Ant文件? Maybe even shutdown and restart my Java EE server before and after building? 甚至在构建前后都可以关闭并重新启动Java EE服务器?

I'd like to double-click just once and have my toolchain work, while I... get myself another cup of coffee. 我只想双击一次即可使用我的工具链,而我...自己再喝杯咖啡。

I can think of two options: 我可以想到两种选择:

  1. Write a wrapper Ant script/target that calls the others in the desired order. 编写一个包装Ant脚本/目标,以所需的顺序调用其他脚本/目标。 It's been a number of years since I wrote any Ant but I remember doing that, probably using the <ant> task . 自从我编写任何Ant以来已经有很多年了,但我记得这样做了,可能是使用<ant>任务 It might make sense to simply define a target that has dependencies/prerequisites in the right sequence (in conjunction with the <import> task to pull in the separate buildfiles). 仅按正确的顺序定义具有依赖项/先决条件目标 (与<import>任务结合以提取单独的构建文件)可能是有意义的。 Here is a discussion about the difference between these two approaches. 这是关于这两种方法之间差异的讨论

  2. Use Eclipse's External Tool feature to invoke a batch/shell script that calls each Ant target. 使用Eclipse的外部工具功能来调用一个批处理/ shell脚本,该脚本调用每个Ant目标。

This is what I finally came up with: 这是我最终想出的:

<project default="all" basedir=".." name="Build all projects">

  <property name="folder.project.a" value="MyProjectA" />
  <property name="folder.project.b" value="MyOtherProjectB" />

  <!-- Target to build all projects -->
  <target name="all" depends="projectA, projectB" />

  <target name="projectA">
    <echo>Building project A.</echo>
    <ant antfile="${folder.project.a}/my_build_file.xml" />
  </target>

  <target name="projectB">
    <echo>Building project B.</echo>
    <ant antfile="${folder.project.b}/my_other_build_file.xml" />
  </target>

</project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM