【问题标题】:Maven: NoClassDefFoundError of system scoped dependencyMaven:系统范围依赖的 NoClassDefFoundError
【发布时间】:2015-06-11 07:23:46
【问题描述】:

我正在使用 Maven 开发一个 Android 项目。我有一个第三方 jar 文件,已包含在我的项目根目录的 lib 文件夹中:

 <dependency>
     <groupId>com.parse</groupId>
     <artifactId>parse</artifactId>
     <version>1.9.2</version>
     <scope>system</scope>
     <systemPath>${project.basedir}\lib\Parse-1.9.2.jar</systemPath>
 </dependency>

但是当我在手机中安装 apk 时,我得到了NoClassDefFoundError。显然,该类存在于 jar 中。

我该怎么办?

谢谢。

【问题讨论】:

  • 将范围更改为提供并再次测试
  • 构建错误:'dependencies.dependency.systemPath' for com.parse:parse:jar must be omitted. This field may only be specified for a dependency with system scope
  • 您还需要删除 标签并将 jar 加载到本地 maven repo 中。
  • 请检查编译而不是系统,看看会发生什么
  • @DSF 是的,我想我会尝试将 jar 安装到我的 repo 中,而不是这个。

标签: java android maven


【解决方案1】:

我建议使用您的目录之一作为存储库,在其中添加您的 jar,然后以正确的 Maven 方式加载它。

您可以将其添加到您的 pom.xml 并将您的 jar 放入 /lib:

<repositories>
   <repository>
       <id>mylibid</id>
       <url>file://${project.basedir}/lib</url>
   </repository>
</repositories>

...

<dependencies>
  ...
  <dependency>
      <groupId>com.parse</groupId>
      <artifactId>parse</artifactId>
      <version>1.9.2</version>
  </dependency>
  ...
</dependencies>

【讨论】:

    【解决方案2】:

    在这里添加我的两分钱,you can install the third-party into your local repository 首先尝试直接添加依赖项。

    以您的场景为例。切换到包含第三个 jar 的文件夹并输入:

    mvn install:install-file -DgroupId=com.parse -DartifactId=parse -Dversion=1.9.2 -Dpackaging=jar -Dfile=Parse-1.9.2.jar

    修改您的pom.xml 以添加依赖项。

    <dependencies>
      ...
      <dependency>
          <groupId>com.parse</groupId>
          <artifactId>parse</artifactId>
          <version>1.9.2</version>
      </dependency>
      ...
    </dependencies>
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2012-05-17
      • 2015-09-16
      • 2011-02-05
      • 2012-05-21
      • 2023-04-04
      相关资源
      最近更新 更多