如何在 maven 中执行多个蚂蚁目标 [英] How to execute multiple ant targets in maven

查看:27
本文介绍了如何在 maven 中执行多个蚂蚁目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,是的,这是一个 XY 类型的问题.(我想在不丢失任何信息的情况下更好地呈现它)

Yes, yes, this is a XY type of problem. (I wanted to present it nicer without loosing any information)

在我的项目中,当我尝试在 maven 中执行 ANT 任务时,它给了我与本示例中相同的错误.我从 这里 中获取了这个示例.

In my project when I tried to execute the ANT tasks in maven it gives me the same error that I have in this sample. I took this example from here.

我尝试使用 maven-antrun-plugin 执行多个 ant 目标,如下所示.但是,它总是只执行最下面的目标(当我没有提到依赖属性时).当我使用它时,它给出以下异常:

I tried to execute the multiple ant targets using the maven-antrun-plugin as below. But, it always executes the below most target only (when I don't mention depends attibute). When I use it, it gives following exception :

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project jibx-mvn-demo: An Ant BuildException has occured: Target "compile" does not exist in the project "maven-antrun-". It is used from target "myDAO". -> [Help 1]

pom.xml

    <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>install</phase>
                    <configuration>
                        <target name="clean">
                            <echo>Clean up my working directory to be nice and sparkly</echo>
                        </target>
                        <target name="initDAO">
                            <echo>Initialize stuff for my DAO build</echo>
                            <echo>Maybe setup some properties?</echo>
                        </target>
                        <target name="makedir" depends="initDAO">
                            <echo>I need my directories for building.</echo>
                            <echo>But first, I need to setup stuff"</echo>
                        </target>
                        <target name="compile" depends="makedir">
                            <echo>I need to compile my dao source"</echo>
                            <echo>But first, I need to make the necessary directories</echo>
                        </target>
                        <target name="myDAO" depends="compile">
                            <echo>Here's where I package up my DAO</echo>
                            <echo>But I have to compile stuff before I can package it</echo>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这是什么原因?如何在 maven 中执行多个 ant 任务?

What is the reason for this? How can I execute multiple ant tasks in maven?

推荐答案

这个答案在当前版本的 Maven AntRun 插件 (1.8) 中对我不起作用,我想念 build.xml 文件.

The answer not work for me in the current version of Maven AntRun plugin (1.8) and I miss how would be the build.xml file.

所以,在 pom.xml 中:

So, in the pom.xml:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>download-files</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <ant antfile="build.xml">
                        <target name="go"/>
                    </ant>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

以及 build.xml 文件:

And the build.xml file:

<project name="Selenium" basedir=".">

    <target name="check-files">
        <available file="src/test/resources/firefox/firefox" property="firefox.exists"/>
    </target>

    <target name="download-firefox" depends="check-files" unless="firefox.exists">
        <!-- download Firefox for selenium -->
        <get src="https://ftp.mozilla.org/pub/firefox/releases/57.0/linux-x86_64/pt-BR/firefox-57.0.tar.bz2"
             dest="src/test/resources"
             verbose="false"
             usetimestamp="true"/>
        <bunzip2 src="src/test/resources/firefox-57.0.tar.bz2"
                 dest="src/test/resources"/>
        <untar src="src/test/resources/firefox-57.0.tar"
               dest="src/test/resources"/>
        <chmod file="src/test/resources/firefox/firefox/" perm="700"/>
    </target>

    <target name="go" depends="check-files, download-firefox"/>

</project>

以上示例执行以下任务:

The above example execute the follow tasks:

  1. 检查src/test/resources上是否存在firefox;
  2. 如果不存在:
  1. Check if firefox exists on src/test/resources;
  2. If not exists:
  1. 下载火狐;
  2. bunzip2 firefox bzip2 文件;
  3. untar Firefox tar 文件;
  4. 使用chmod命令调整文件夹权限.
  1. Download firefox;
  2. bunzip2 firefox bzip2 file;
  3. untar the firefox tar file;
  4. Adjust the folder permission using chmod command.

完美运行!

这篇关于如何在 maven 中执行多个蚂蚁目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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