通过命令行参数更改默认蚂蚁目标 [英] Change default ant target by command line argument

查看:26
本文介绍了通过命令行参数更改默认蚂蚁目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近接到了一项任务,让 ant 能够为不同的环境构建 war 包.除了一项功能外,我几乎完成了.

I'm recently assigned a task to make ant be able to build war packages for different environments. I'm almost done except one feature.

蚂蚁通过like -Denv=DEV接受一个env参数,并使用不同的配置文件来制作war包.但是默认目标是 start 它将构建、部署和启动 tomcat.当我传入 -Denv=PROD arg 时,我不希望 ant 部署战争也不启动服务器.我只想用蚂蚁来构建ROOT.war.够了.

The ant accepts an env parameter by like -Denv=DEV, and use different configuration files to make the war package. But the default target is start which will build, deploy and start the tomcat. I don't want ant to deploy the war neither start the server when I pass in the -Denv=PROD arg. I only want ant to build the ROOT.war. It's enough.

我知道我可以再输入一个词来实现这个目标,但你知道我们都很懒惰.:D

I know I can just type one more word to achieve this goal, but you know we are all lazy. :D

有谁知道如何根据命令行参数更改默认目标?我的要求如下:

Does anyone know how to change the default target according to the command line argument? My requirements are as below:

  1. ant -Denv=DEV 将构建、部署和启动服务器
  2. ant -Denv=PROD 只会构建 ROOT.war
  1. ant -Denv=DEV will build, deploy, and start the server
  2. ant -Denv=PROD will only build the ROOT.war

推荐答案

我建议您在名为DEV"和PROD"的 build.xml 文件中定义目标,然后调用 Ant 为:

I suggest that you define targets in your build.xml file called "DEV" and "PROD" and then invoke Ant as:

ant DEV

ant PROD

如果您想坚持使用系统属性来选择目标的当前方法,那么@krock 的答案似乎是要走的路.(但我认为这种方法没有任何优势.)

If you want to stick with your current approach of using a system property to select the target, then @krock's answer seems to be the way to go. (But I don't see any advantage in that approach though.)

这篇关于通过命令行参数更改默认蚂蚁目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆