3

我使用 install:install-file 将 jar 安装到我的本地存储库。我的 pom.xml 编写如下:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
    <execution>
    <id>install-paho</id>
    <phase>generate-resources</phase>
    <goals>
        <goal>install-file</goal>
    </goals>
    <configuration>
        <file>${basedir}/lib/paho.jar</file>
        <groupId>org.eclipse</groupId>
        <artifactId>paho</artifactId>
        <version>1.0.0</version>
        <packaging>jar</packaging>
    </configuration>
    </execution>
</executions>
</plugin>

你可以发现我将它绑定到阶段'generate-resources'。然后,我使用 order 。mvn eclipse:eclipse它工作得很好,jar 被复制到我的本地存储库。但是当我使用 order 时,mvn install:install-file我得到了错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file (default-cli) on project xxx: 
The parameters 'file' for goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are missing or invalid -> [Help 1]

使用时的错误信息mvn compile

[ERROR] Failed to execute goal on project android-engine: Could not resolve dependencies    for project com.youku.wireless:android-engine:jar:1.0-SNAPSHOT: Could not find artifact org.eclipse:paho:jar:1.0.0 in spring-milestone (http://maven.springframework.org/milestone) ->   [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]     http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
4

1 回答 1

10

由于您已将目标绑定install:install-filegenerate-sources阶段,因此您应该运行mvn compilemvn install使用定义的配置。

mvn eclipse:eclipse之所以有效,是因为 Maven 在generate-sources调用eclipse:eclipse.

编辑: 从评论看来,您希望paho.jar通过首先将其安装到generate-sources阶段中的本地存储库,然后将其用作项目中的项目来使用项目中的本地可用dependency

这是行不通的,因为 mavendependencies在开始执行其生命周期目标之前会检查可用性。

mvn install:install-file您可以在 pom 的上下文之外使用一次性手动安装它。更好的是,您可以将它部署到 arepository manager然后像任何其他依赖项一样访问它。

但是,如果您仍想走这条路,另一种方法是使用system提供 jar 路径的范围来指定依赖项。参考这个

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>paho</artifactId>
      <version>1.0.0/version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/paho.jar</systemPath>
    </dependency>
  </dependencies>
  ...
</project>
于 2012-06-08T09:25:16.057 回答