Maven Antrun和Dependencies

时间:2009-10-16 21:35:56

标签: ant dependencies maven-2 maven-antrun-plugin

(请参阅下面的编辑。)

我不能只使用类路径的原因是因为我需要管理一些非java库,而且我正在编译一个非java项目。

我正在尝试在antrun调用中使用maven依赖项,遵循maven站点上的文档:

http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

在页面底部:

<property name="mvn.dependency.jar" 
      refid="maven.dependency.my.group.id:my.artifact.id:classifier:jar.path"/>
<echo message="My Dependency JAR-Path: ${mvn.dependency.jar}"/> 

无论我如何尝试,我都无法完成这项工作。我已经在refid内容周围尝试了$ {},我尝试过冒号,句号等等。作为我能想到的各种方式的分隔符。

任何人都可以告诉我,对于某些常见的依赖,真的看起来应该是什么样的?

修改

感谢您的回复。

使用您的示例SingleShot,我有以下内容:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>create-messages</id>
        <phase>compile</phase>
        <configuration>
          <tasks>
            <property name="build.compiler" value="extJavac"/>
            <property name="compile_classpath" refid="maven.compile.classpath"/>
            <property name="runtime_classpath" refid="maven.runtime.classpath"/>
            <property name="test_classpath" refid="maven.test.classpath"/>
            <property name="plugin_classpath" refid="maven.plugin.classpath"/>

            <property name="log4j.jar" refid="log4j:log4j:jar"/>
            <echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
      </dependency>
    </dependencies>
  </plugin>

这就是我在运行mvn compile时得到的结果:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Chat Component
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K downloaded
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K downloaded
[INFO] [antrun:run {execution: create-messages}]
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: Reference log4j:log4j:jar not found.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Oct 16 14:54:19 PDT 2009
[INFO] Final Memory: 7M/80M
[INFO] ------------------------------------------------------------------------

编辑(2):

查看链接的源代码,我决定运行“mvn -X compile”和grep for“Storing”,这会产生一堆日志输出,存储起来。

有趣的是我明确指定的依赖关系没有显示在列表中的事实,并且当我根据我看到的其中一个条目切换到一个键时,我仍然得到错误。

5 个答案:

答案 0 :(得分:4)

作为Aaron H.上面回答的附录,我不得不将插件的版本设置为1.3,以便实际工作。我在没有特定版本的情况下使用它并获得1.1(似乎没有任何效果)。


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        ...
      </plugin>

答案 1 :(得分:2)

如果没有您在POM中输入的内容的例子很难说,但请考虑一个具体的例子。假设您的POM引用了log4j(groupId = log4j,artifactId = log4j)。我相信这就是你在Ant文件中引用JAR的方式:

<property name="log4j.jar" refid="maven.dependency.log4j:log4j:jar.path"/>
<echo message="Where is the Log4J JAR?: ${log4j.jar}"/>

理想情况下,您不必引用特定的JAR,而是引用适当范围的整个类路径,因为插件的文档有点稀疏。

如果您仍然遇到问题,请发布您正在使用的Maven POM依赖关系的<dependency>标记,我可以尝试更具体。

我查看了plugin's code以确认。

答案 2 :(得分:2)

这适合我。

<copy file="${javax.mail:javax.mail-api:jar}" todir="tomcat/lib" />
<copy file="${org.springframework:spring-instrument-tomcat:jar}" todir="tomcat/lib" />
<copy file="${postgresql:postgresql:jar}" todir="tomcat/lib"/>

http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html解释了如何从ant类路径引用依赖项。

答案 3 :(得分:1)

有一个bug in the documentation。路径应为以下形式:

<property name="mvn.dependency.jar" 
  value="${maven.dependency.my.group.id.my.artifact.id.classifier.jar.path}"/>

因此,log4j依赖关系的正确键是:

maven.dependency.log4j.log4j.jar.path

另请注意,它应为value=而不是refid=,因此完整属性为:

<property name="log4j.jar" 
      value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="My Dependency JAR-Path: ${log4j.jar}"/> 

答案 4 :(得分:0)

我有一只现有的蚂蚁,我们计划使用(新)maven来调用它。我遇到了一些我可能记不清楚的问题,但它与课程相关,可能和你的一样。

问题是,我们每天使用的“ant”是一个shell脚本,可以在XNIX和Windows上设置类pathes。我没有比较它设置的类和maven可用的类,但我的测试显示它们不匹配,并且ant不会运行从maven传递给它的一些pathes。

我使用的是“exec-maven-plugin”并将ant作为外部程序运行,并应用了一些参数。这肯定会起作用,但会增加额外的依赖性。