我如何通过Maven的执行简单的蚂蚁电话? [英] How do I execute simple ant call through maven?

查看:269
本文介绍了我如何通过Maven的执行简单的蚂蚁电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目运行具有以下命令完美的罚款:

  C:\\项目\\<&PROJECT_NAME GT; \\蚂蚁蚂蚁-lib \\ lib中-buildfile应用/<副项目路径> /ant/build.xml部署

不过,如果我在POM包装这个命令无论是在Maven的antrun-插件或者exec-Maven的插件,我得到的各种路径的问题。

有关Maven的antrun-插件,似乎某些属性不能被加载,由于路径问题。在EXEC-Maven的插件,似乎蚂蚁的目标从来没有得到正确地传递。结果
可有人请的意见,我怎么能在一个POM文件应用此?大部分AP preciated。

这是我的EXEC POM:

 <建立>
    <&插件GT;
        <&插件GT;
            <的groupId方式>组织codehaus.mojo< /的groupId>
            <&的artifactId GT;的exec-Maven的插件< / artifactId的>
            <&版GT; 1.2.1< /版本>
            <&执行GT;
                <执行与GT;
                    <阶段>的过程,资源和LT; /阶段>
                    <目标>
                        <&目标GT; EXEC< /目标>
                    < /目标>
                    <结构>
                    <可执行指令GT;蚂蚁< /可执行>
                    <&工作目录GT; $ {BASEDIR}< /工作目录>
                    <&参数GT;
                        <&说法GT;' - 蚂蚁的lib / lib目录'< /参数>
                        &LT;&说法GT;' - 构建文件$ BASEDIR /&LT;项目路径&GT; /build.xml'< /参数&GT;
                        &LT;&说法GT;&部署LT; /参数&GT;
                    &LT; /参数&GT;
                    &LT; /结构&gt;
                &LT; /执行&GT;
            &LT; /处决&GT;
        &LT; /插件&GT;
    &LT; /插件&GT;
&LT; /构建&GT;


解决方案

您应该传递需要依赖直接进入antrun插件声明,之后&LT;执行方式&gt; 元素

 &LT;&插件GT;
        &LT;的groupId方式&gt;组织codehaus.mojo&LT; /的groupId&GT;
        &LT;&的artifactId GT;的exec-Maven的插件&LT; / artifactId的&GT;
        &LT;&版GT; 1.2.1&LT; /版本&GT;
        &LT;&执行GT;
            ...
        &LT; /处决&GT;
        &LT;依赖和GT;
          &LT;&依赖性GT;
            &LT;&的groupId GT;蚂蚁的contrib&LT; /的groupId&GT;
            &LT;&的artifactId GT;蚂蚁的contrib&LT; / artifactId的&GT;
            &LT;&版GT; $ {蚂蚁contrib.version}&LT; /版本&GT;
            &LT;&排除GT;
              &LT;&排斥GT;
                &LT;&的groupId GT;蚂蚁&LT; /的groupId&GT;
                &LT;&的artifactId GT;蚂蚁&LT; / artifactId的&GT;
              &LT; /排除&GT;
            &LT; /排除&GT;
          &LT; /依赖性&GT;
          &LT;&依赖性GT;
            &LT;&的groupId GT; org.apache.tomcat&LT; /的groupId&GT;
            &LT;&的artifactId GT;碧玉&LT; / artifactId的&GT;
            &LT;&版GT; $ {tomcat.compile.version}&LT; /版本&GT;
          &LT; /依赖性&GT;
          &LT;&依赖性GT;
            &LT;&的groupId GT;的com.sun&LT; /的groupId&GT;
            &LT;&的artifactId GT;工具和LT; / artifactId的&GT;
            &LT;&版GT; $ {} java.version和0.0 LT; /版本&GT;
            &LT;&范围GT;系统和LT; /&范围GT;
            &LT; Systempath下&GT; $ {} jdk.home /tool​​s.jar</systemPath>
          &LT; /依赖性&GT;
        &LT; /依赖和GT;
    &LT; /插件&GT;

我已经包括了一些图书馆,我在我们的项目中使用,让你有一个例子。请注意,如果你的构建使用了一些不规范的Java API类(即的java.lang 之外的东西),你必须通过的tools.jar 作为一个依赖。

此外,如果使用蚂蚁的contrib 不要忘了排除蚂蚁作为依赖,因为它是依赖于一些古代版本的蚂蚁,你会得到一个版本冲突。

另一个讨厌的就是直接分配给插件执行这种依赖性不会POM的&LT的一部分; dependencyManagement&GT; ,所以你必须拼出precise版本。一个解决办法是为您的中心&LT声明在同一个地方版的性能; dependencyManagement方式&gt; 和使用属性,而不是硬codeD版本

My project runs perfectly fine with following commands:

C:\project\<project_name>\ant -lib ant\lib -buildfile applications/<sub-project-path>/ant/build.xml deploy

However, if I wrap this command either in maven-antrun-plugin or exec-maven-plugin in pom, I get all kinds of path issues.

For maven-antrun-plugin, it seems the certain properties can not be loaded due to path issue. In exec-maven-plugin, it seems that ant target never got passed in correctly.
Can someone please advice how I can apply this in a pom file? Much appreciated.

This is my pom for exec:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                    <executable>ant</executable>
                    <workingDirectory>${basedir}</workingDirectory>
                    <arguments>
                        <argument>'-lib ant/lib'</argument>
                        <argument>'-buildfile $basedir/<project-path>/build.xml'</argument>
                        <argument>deploy</argument>
                    </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

解决方案

You should pass needed dependencies directly into antrun plugin declaration, right after <executions> element.

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
            ...
        </executions>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>${ant-contrib.version}</version>
            <exclusions>
              <exclusion>
                <groupId>ant</groupId>
                <artifactId>ant</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>jasper</artifactId>
            <version>${tomcat.compile.version}</version>
          </dependency>
          <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>${java.version}.0</version>
            <scope>system</scope>
            <systemPath>${jdk.home}/tools.jar</systemPath>
          </dependency>
        </dependencies>
    </plugin>

I've included some libraries that I use in our project, so that you have an example. Note, that if your build uses some non-standard ( i.e. something outside java.lang ) Java API classes, you have to pass tools.jar as a dependency.

Also, if you use ant-contrib do not forget to exclude ant as a dependency, because it is dependent on some ancient version of ant and you will get a version collision.

Another annoying thing is that dependency assigned directly to plugin execution are not part of POM's <dependencyManagement>, so you have to spell out precise versions. One workaround is to declare version properties in the same place as your central <dependencyManagement> and use the properties instead of hardcoded versions.

这篇关于我如何通过Maven的执行简单的蚂蚁电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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