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

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

问题描述

我的项目使用以下命令运行得非常好:

C:\project\\ant -lib ant\lib -buildfile applications//ant/build.xml deploy

但是,如果我将此命令包装在 maven-antrun-plugin 或 exec-maven-plugin 中,我会遇到各种路径问题.

对于 maven-antrun-plugin,似乎由于路径问题无法加载某些属性.在 exec-maven-plugin 中,似乎 ant 目标从未正确传入.
有人可以建议我如何在 pom 文件中应用它吗?非常感谢.

这是我用于 exec 的 pom:

<插件><插件><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.2.1</version><执行><执行><phase>处理资源</phase><目标><目标>执行</目标></目标><配置><executable>ant</executable><workingDirectory>${basedir}</workingDirectory><参数><argument>'-lib ant/lib'</argument><argument>'-buildfile $basedir/<project-path>/build.xml'</argument><参数>部署</参数></参数></配置></执行></执行></插件></plugins></build>

解决方案

您应该将需要的依赖项直接传递到 antrun 插件声明中,紧跟在 元素之后.

 <插件><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.2.1</version><执行>...</执行><依赖项><依赖><groupId>ant-contrib</groupId><artifactId>ant-contrib</artifactId><version>${ant-contrib.version}</version><排除事项><排除><groupId>ant</groupId><artifactId>ant</artifactId></排除></排除项></依赖><依赖><groupId>org.apache.tomcat</groupId><artifactId>jasper</artifactId><version>${tomcat.compile.version}</version></依赖><依赖><groupId>com.sun</groupId><artifactId>工具</artifactId><version>${java.version}.0</version><范围>系统</范围><systemPath>${jdk.home}/tools.jar</systemPath></依赖></依赖项></插件>

我已经包含了一些我在我们的项目中使用的库,所以你有一个例子.请注意,如果您的构建使用一些非标准(即 java.lang 之外的东西)Java API 类,您必须将 tools.jar 作为依赖项传递.>

另外,如果你使用 ant-contrib 不要忘记排除 ant 作为依赖,因为它依赖于一些古老的 ant 版本,你会得到一个版本冲突.

另一个烦人的事情是,直接分配给插件执行的依赖不是 POM 的 的一部分,所以你必须拼出精确的版本.一种解决方法是在与中央 相同的位置声明版本属性,并使用这些属性而不是硬编码版本.

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天全站免登陆