Maven ANT 项目
使 Ant 项目变得更加自动化的正确方法是什么?该项目有一个包含 3 个目标的 Ant build.xml 文件。
我已经找到了如何配置 pom.xml 来运行 Ant 任务,但让我担心的是: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html: "maven-antrun-plugin 只有一个目标,运行。"
是否可以在我的 pom.xml 文件中定义 3 个 ant 任务并根据参数/属性决定运行哪个目标?我应该考虑使用配置文件吗?
What's a proper way of mavenizing an Ant project? the project has an Ant build.xml file with 3 targets.
I've found out how to configure the pom.xml to run Ant tasks, but what worries me is this: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html: "the maven-antrun-plugin has only one goal, run."
Is it possible to define 3 ant tasks in my pom.xml file and decide which target to run, based on a parameter/property? should I consider using profiles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于任务。据推测,您的 3 个 ant 目标正在执行 3 个不同的构建。您可以使用配置文件轻松实现这一点(这就是它们的用途)。如果你做得正确,你根本就不会使用 maven-antrun-plugin。相反,您可以使用标准 Maven 插件来生成工件(maven-jar-plugin、maven-war-plugin、maven-ear-plugin、程序集插件等),具体取决于您实际尝试生成的内容。
查看“使用 Maven 进行更好的构建”pdf,它可以在线免费获取,非常适合 Maven 初学者。
It depends on the tasks. Presumably, your 3 ant targets are doing 3 different builds. You could accomplish that with profiles easily (that's what they're for). If you do it right, you wouldn't use the maven-antrun-plugin at all. You'd instead be using the standard maven plugins for generating the artifacts (maven-jar-plugin, maven-war-plugin, maven-ear-plugin, assembly plugin, etc) depending on what you're trying to actually generate.
Check out the "better builds with maven" pdf, it's available free online and is great for maven beginners.
您可以首先查看此 SO 讨论 - Mavenize 意味着什么一个项目。通过maven(使用maven antrun插件)运行ant脚本并不完全是mavenizing。
您的构建脚本包含三个任务。如果它们很简单,如
clean
、compile
、jar
- 那么 maven 将所有这些作为其默认构建生命周期的一部分。您所需要的只是创建一个 pom 文件并定义所需的依赖项。如果ant任务正在做更复杂的事情,而maven无法实现,那么你仍然可以考虑使用maven antrun插件。
您想独立构建这三个任务吗?如果是这样,配置文件是一种方法。如果任务相互依赖,那么您只需从 maven antrun 插件调用该任务,该插件将依次调用依赖的任务。
You could start by looking at this SO discussion - What does it meant o Mavenize a project. Running an ant script through maven (using maven antrun plugin) is not exactly mavenizing.
Your build script has three tasks. If they are something as simple, as
clean
,compile
,jar
- then maven does all these as part of its default build lifecycle. All you would need is to create a pom file and define the required dependencies.If the ant tasks are doing more complicated things, which cannot be achieved by maven, then you could still look at using the maven antrun plugin.
Would you want to build the three tasks independently? If so, profiles is one way to go. If the tasks are dependent on each other, then you would just want to invoke that task from maven antrun plugin, which will in turn call the dependent tasks.