【发布时间】:2012-03-05 13:47:18
【问题描述】:
我有一个项目使用一些遗留脚本来处理源代码。我无法摆脱它,所以我想从 maven 中调用它。
问题是我需要将 jar 文件的位置作为参数传递。我已将此 jar 文件列为我的 pom.xml 中的依赖项。有没有办法可以将 jar 文件的绝对位置传递给这个脚本?
【问题讨论】:
标签: maven
我有一个项目使用一些遗留脚本来处理源代码。我无法摆脱它,所以我想从 maven 中调用它。
问题是我需要将 jar 文件的位置作为参数传递。我已将此 jar 文件列为我的 pom.xml 中的依赖项。有没有办法可以将 jar 文件的绝对位置传递给这个脚本?
【问题讨论】:
标签: maven
这绝不是理想的,但您可以从 maven 调用您的脚本,并将其作为参数传递:
${settings.localRepository}/<path to artifact>
artifact 的路径是由你想要的组 id 和 artifact id 组成的路径。例如,如果您想引用 maven-jar-plugin 2.2 版,您可以使用:
${settings.localRepository}/org/apache/maven/plugins/maven-jar-plugin/2.2/maven-jar-plugin-2.2.jar
【讨论】:
我更喜欢Pascal Thivent's answer 来回答类似的问题。您可以使用 ${maven.dependency.junit.junit.jar.path} 表示法来引用依赖项。 Pascal 在他的回答中包含了一个示例 pom:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2359872</artifactId>
<version>1.0-SNAPSHOT</version>
<name>q2359872</name>
<properties>
<my.lib>${maven.dependency.junit.junit.jar.path}</my.lib>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<echo>${my.lib}</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
【讨论】: