eclipse 如何使用蚂蚁?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/694846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:36:44  来源:igfitidea点击:

How to use Ant?

javaeclipseantbuild-processbuild-automation

提问by Click Upvote

I've been trying to understand what Ant is used for but i still don't get it.

我一直试图了解 Ant 的用途,但我仍然不明白。

Can someone give me one use case for which Ant is used for, something I can try to see why Ant is useful and what kind of things I can use it for?

有人可以给我一个使用 Ant 的用例吗,我可以尝试看看为什么 Ant 有用以及我可以用它做什么?

I do Java development in Eclipse and I'm just getting started with servlets and Google Web Toolkit.

我在 Eclipse 中进行 Java 开发,我刚刚开始使用 servlets 和 Google Web Toolkit。

回答by Ted Dziuba

Ant is a build tool. Say for example you have several projects in your Eclipse workspace, all of which are pieces of a larger application. To build it all into a jar file with dependencies included, you could select all the projects and export them as a jar file, but that's somewhat cumbersome.

Ant 是一个构建工具。例如,假设您的 Eclipse 工作区中有多个项目,所有这些项目都是一个较大应用程序的组成部分。要将其全部构建到包含依赖项的 jar 文件中,您可以选择所有项目并将它们导出为 jar 文件,但这有点麻烦。

Ant is an extensible solution. You define the build process in XML, and ant compiles your java files according to this recipe.

Ant 是一个可扩展的解决方案。你用 XML 定义构建过程,ant 根据这个秘籍编译你的 java 文件。

Ant can do more than building, too. I worked at a company where the mechanism for deployment was Debian packages in our own repository. We had Ant scripts that would build the jar files, arrange them and some metadata files into a Debian package, put them into the repository, and re-generate the repository manifest.

Ant 还可以做更多的事情。我在一家公司工作,该公司的部署机制是我们自己存储库中的 Debian 软件包。我们有 Ant 脚本,可以构建 jar 文件,将它们和一些元数据文件排列到 Debian 包中,将它们放入存储库,然后重新生成存储库清单。

As with anything Java, there's a lot of configuration you need to get your head around before you're proficient with Ant, but some of the basic tutorials should give you an idea of what you're getting yourself into.

与任何 Java 一样,在您精通 Ant 之前,您需要了解很多配置,但是一些基本教程应该可以让您了解自己在做什么。

回答by TofuBeer

Ant is used, as any build tool is, to automate the repetitive tasks of building your code.

与任何构建工具一样,Ant 用于自动执行构建代码的重复任务。

Rather than run javac each time by hand you put a command into an Ant script and then when you run ant it will run javac for you.

您不必每次都手动运行 javac,而是将命令放入 Ant 脚本中,然后当您运行 ant 时,它会为您运行 javac。

My typical build process with ant goes something like this:

我使用 ant 的典型构建过程是这样的:

  • run javac on the source
  • run javac on the tets
  • run the cobertura instrumentation on the source (this is for code coverage)
  • jar up the classes from the source
  • jar up the cobertura instrumented classes
  • jar up the unit test classes
  • run checkstyle, pmd, findbugs on the source to find warnings
  • run the unit tests via cobertura to get code coverage of them
  • 在源代码上运行 javac
  • 在 tets 上运行 javac
  • 在源代码上运行 cobertura 检测(这是为了代码覆盖率)
  • 从源代码中提取类
  • 振奋 cobertura 检测类
  • jar up 单元测试类
  • 在源代码上运行 checkstyle、pmd、findbugs 以查找警告
  • 通过 cobertura 运行单元测试以获得它们的代码覆盖率

So that is 8 steps that I have done on each build that I can do simply by running "ant".

所以这是我在每个构建中完成的 8 个步骤,我可以通过运行“ant”来完成。

回答by duffymo

Ant is an XML-based make file.

Ant 是一个基于 XML 的 make 文件。

You won't see much benefit using Ant if you're a single developer who already builds and packages code successfully using an IDE like Eclipse.

如果您是一个已经使用 Eclipse 之类的 IDE 成功构建和打包代码的单一开发人员,那么使用 Ant 将看不到太多好处。

The larger benefit comes when you have a team collaborating on code. Then you'll get a big boost if you use Cruise Control or some other continuous integration facility. CC requires an Ant build.xml.

当您有一个团队在代码上进行协作时,更大的好处就来了。如果您使用 Cruise Control 或其他一些持续集成工具,那么您将获得巨大的提升。CC 需要一个 Ant build.xml。

回答by ReneS

This is from the ANT documentation and explains it pretty well.

这是来自 ANT 文档并很好地解释了它。

Why another build tool when there is already make, gnumake, nmake, jam, and others? Because all those tools have limitations that Ant's original author couldn't live with when developing software across multiple platforms. Make-like tools are inherently shell-based: they evaluate a set of dependencies, then execute commands not unlike what you would issue on a shell. This means that you can easily extend these tools by using or writing any program for the OS that you are working on; however, this also means that you limit yourself to the OS, or at least the OS type, such as Unix, that you are working on.

Makefiles are inherently evil as well. Anybody who has worked on them for any time has run into the dreaded tab problem. "Is my command not executing because I have a space in front of my tab?!!" said the original author of Ant way too many times. Tools like Jam took care of this to a great degree, but still have yet another format to use and remember.

Ant is different. Instead of a model where it is extended with shell-based commands, Ant is extended using Java classes. Instead of writing shell commands, the configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by an object that implements a particular Task interface.

Granted, this removes some of the expressive power that is inherent in being able to construct a shell command such as find . -name foo -exec rm {}, but it gives you the ability to be cross-platform--to work anywhere and everywhere. And hey, if you really need to execute a shell command, Ant has an task that allows different commands to be executed based on the OS it is executing on.

当已经有 make、gnumake、nmake、jam 和其他工具时,为什么还要使用另一个构建工具?因为所有这些工具都有一些限制,Ant 的原作者在跨多个平台开发软件时无法忍受。类似 Make 的工具本质上是基于 shell 的:它们评估一组依赖项,然后执行与您在 shell 上发出的命令不同的命令。这意味着您可以通过使用或为您正在使用的操作系统编写任何程序来轻松扩展这些工具;然而,这也意味着您将自己限制在操作系统,或者至少是您正在使用的操作系统类型,例如 Unix。

Makefile 本质上也是邪恶的。任何为它们工作过的人都会遇到可怕的标签问题。“我的命令没有执行是因为我的选项卡前面有一个空格吗?!!” Ant方式的原作者说了太多次了。像 Jam 这样的工具在很大程度上解决了这个问题,但仍然有另一种格式可以使用和记住。

蚂蚁不一样。Ant 不是使用基于 shell 的命令扩展的模型,而是使用 Java 类扩展的。配置文件不是编写 shell 命令,而是基于 XML 的,调用执行各种任务的目标树。每个任务都由一个实现特定任务接口的对象运行。

诚然,这消除了构建 shell 命令(例如 )所固有的一些表达能力find . -name foo -exec rm {},但它使您能够跨平台——随时随地工作。嘿,如果你真的需要执行一个 shell 命令,Ant 有一个任务,允许根据它正在执行的操作系统执行不同的命令。