Ant task vs Shell script

2019-07-16 01:36发布

I see a lot of places in my office where ant tasks are used to move files from one place to another and also do some tasks on these files.However all this can be done with shell scripts.

My question is ,

In what cases is ant preferred over shell scripts ?

What are the benefits of using ant over a shell scripts for doing same set of tasks.

One advantage ant has is that it works on all platforms,other than that are there any performance related advantages ?

2条回答
Rolldiameter
2楼-- · 2019-07-16 02:01

In practice, it boils down to Windows support. If you're in a Unix shop and don't want to introduce new stuff to devs, there are two alternatives i've used with success:

  • Plain old shell script with Git Bash. Git Bash comes with the Git windows distribution (http://git-scm.com/). If you're doing automation, you can launch shell scripts like so: "C:\Program Files (x86)\Git\bin\sh.exe" --login -i -- ./BUILD

  • Node script. Again it's one easy installer, it's javascript, and you can use something like ShellJS (https://github.com/arturadib/shelljs) to get very close to Unix shell script / Makefiles.

查看更多
祖国的老花朵
3楼-- · 2019-07-16 02:02

Your question as to why ANT should be preferred to shell scripts is two-fold:

  1. ANT is a tool that has achieved widespread adoption and is likely to be already installed on a developer's workstation. Compared to one of it's main predecessors, make, ANT is a lot more standardized and cross-platform.
  2. ANT is a tool familiar to developers. Used to build their code so they will often extend the ANT script to deploy their application as well. Indeed many vendors offer ANT tasks for this purpose.

There are no performance benefits, really. Java is slow for command-line usage.

But..... I would advise against playing the "performance" card. Let's pretend that your application does not support windows (Which is odd considering a Java application should support all plaforms...): I have seen shell script driven deployments decend into chaos attempting to reconcile the various ways different unix operating system commands work. Commands like "tar", "awk", etc can be subtly different which leads to additional platform support logic in your script.

In conclusion I would use neither. I choose a hybrid approach of using groovy for general scripting. It is a java based scripting language and embeds the full power of ANT. Being a java based scripting language means it will work on all platforms. In the interest of fairness it should also be noted that there are other language options. Ruby is certainly worthy of mention since it has spawned a set of configuration management technologies that are well worth evaluation. (See Chef and Puppet)

查看更多
登录 后发表回答