【问题标题】:how to download jar dependencies while installing jar into m2 repo如何在将jar安装到m2 repo时下载jar依赖项
【发布时间】:2017-03-06 10:38:46
【问题描述】:

我有一个已经在另一台机器上构建的 maven 插件 jar,比如 test-1.0.0.jar。这个 jar 有多个依赖项,如 apache、plexus、maven 等。 例如

<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>3.3.9</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>3.3.9</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-compat</artifactId>
      <version>3.3.9</version>
    </dependency>   
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-embedder</artifactId>
      <version>3.3.9</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-archiver</artifactId>
      <version>2.5</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.5</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>maven-surefire-common</artifactId>
      <version>2.19.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-api</artifactId>
      <version>2.19.1</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-component-annotations</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
       <groupId>org.apache.maven.surefire</groupId>
       <artifactId>surefire-junit47</artifactId>
       <version>2.19.1</version>
    </dependency>
  </dependencies>

现在我想将这个 jar 用于我的 maven 项目,所以我将它安装在我的本地存储库中。当我使用 'mvn install:install-file' 命令安装它时,它不会下载 m2 存储库中 jar 所需的所有依赖项。所以当我在我的新 maven 项目中使用这个插件时,它给了我 classNotFound 异常。

[WARNING] Error injecting: com.test.status.test.MyTestCompileMojo
java.lang.NoClassDefFoundError: org/codehaus/plexus/compiler/util/scan/InclusionScanException

我的项目 POM -

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.check.status</groupId>
  <artifactId>cf</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <build>
    <plugins>
      <plugin>
        <groupId>com.test.status</groupId>
        <artifactId>test</artifactId>
        <version>1.0.0</version>
        <extensions>true</extensions>
       </plugin>
    </plugins>
  </build>
  <dependencies/>
</project>

【问题讨论】:

  • 不能直接运行mvn clean install来安装吗?
  • no.. 我没有代码库.. 我刚刚安装了 jar(使用 mvn clean install),我需要将它安装在我的本地仓库中
  • 但这正是mvn install 所做的...
  • 我正在使用 -'mvn install:install-file -Dfile=test-1.0.0.jar -DgroupId=com.test.status -DartifactId=test -Dversion= 在本地 repo 中安装 jar 文件1.0.0 -Dpackaging=maven-plugin' command .. 它会下载一些依赖项,但不是全部..
  • 请提供有关classNotFound异常的更多信息。

标签: java maven jar dependencies


【解决方案1】:

您应该将您的 test-1.0.0.jar 依赖项添加到您的 pom.xml &lt;dependencies&gt;

使用 -U 参数执行 maven 应该会强制检查远程存储库上丢失的版本和更新的快照。例如:

mvn -U clean install

实际执行目标dependency:resolve只会下载依赖,不做其他任何事情。

mvn dependency:resolve

【讨论】:

  • no.. 我没有代码库。我有一个 jar 文件,我将使用 - 'mvn install:install-file -Dfile=test-1.0.0.jar -DgroupId=com.test.status -DartifactId=test -Dversion=1.0.0 在我的本地仓库中安装它-Dpackaging=maven-plugin'
  • 为什么test-1.0.0.jar 不在您的pom.xml 中?
  • 它就在那里.. 添加在插件部分
  • 将其添加到您的&lt;dependencies&gt;
  • 但我想将它用作我项目的插件
【解决方案2】:

尝试将 test-1.0.0.jar 中的依赖项添加到您的 maven 项目中。

(pom.xml) test-1.0.0.jar  ---copy dependencies---> new maven project

【讨论】:

  • 它会像那样工作..但我不想在我的项目中添加依赖项。
  • @Disha 为什么你不想添加这个依赖。
猜你喜欢
  • 1970-01-01
  • 2012-12-01
  • 2010-09-24
  • 2021-10-25
  • 1970-01-01
  • 2014-04-13
  • 1970-01-01
  • 2020-04-09
  • 2016-01-11
相关资源
最近更新 更多