1

我在构建 android maven 项目(eclipse m2e,android for maven)时遇到问题。

“安装”目标恢复为:

[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Ljavax/persistence/Access;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)

我在项目中添加了以下依赖项:

<dependency>
    <groupId>org.odata4j</groupId>
    <artifactId>odata4j-jersey</artifactId>
    <version>0.7.0</version>
</dependency>

此依赖项还(除其他外)添加了 javax.persistence-2.0.0.jar。

所以我认为图书馆被添加了两次?但是如何解决这个问题呢?当我删除依赖项时,可以毫无错误地构建项目。

这是命令的输出:maven dependency:tree

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ myapp ---
[INFO] org.subby.android:myapp:apk:0.0.1-SNAPSHOT
[INFO] +- com.google.android:android:jar:4.1.1.4:provided
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:provided
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.0.1:provided
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.0.1:provided
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:provided - omitted for  duplicate)
[INFO] |  |  \- commons-codec:commons-codec:jar:1.3:provided
[INFO] |  +- org.khronos:opengl-api:jar:gl1.1-android-2.1_r1:provided
[INFO] |  +- xerces:xmlParserAPIs:jar:2.6.2:provided
[INFO] |  +- xpp3:xpp3:jar:1.1.4c:provided
[INFO] |  \- org.json:json:jar:20080701:provided
[INFO] \- org.odata4j:odata4j-jersey:jar:0.7.0:compile
[INFO]    +- org.odata4j:odata4j-core:jar:0.7.0:compile
[INFO]    |  +- org.core4j:core4j:jar:0.5:compile
[INFO]    |  +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO]    |  +- org.eclipse.persistence:javax.persistence:jar:2.0.0:compile
[INFO]    |  +- org.eclipse.persistence:eclipselink:jar:2.1.2:compile
[INFO]    |  \- joda-time:joda-time:jar:1.6:compile
[INFO]    +- com.sun.jersey:jersey-core:jar:1.1.5:compile
[INFO]    |  \- (javax.ws.rs:jsr311-api:jar:1.1.1:compile - omitted for duplicate)
[INFO]    +- com.sun.jersey:jersey-server:jar:1.1.5:compile
[INFO]    |  +- (com.sun.jersey:jersey-core:jar:1.1.5:compile - omitted for duplicate)
[INFO]    |  \- asm:asm:jar:3.1:compile
[INFO]    \- com.sun.jersey:jersey-client:jar:1.1.5:compile
[INFO]       \- (com.sun.jersey:jersey-core:jar:1.1.5:compile - omitted for duplicate)

难道我做错了什么?我对 Maven 还是很陌生。

谢谢!

4

2 回答 2

2

发生这种情况是因为您的构建中有重复的类。如果您的 Eclipse 类路径包含多个同名/包的类,ADT 将抛出 s。

我建议 mvn dependency:tree在你能得到全貌的地方跑

[INFO] +- com.sun.jersey:jersey:jar:0.8-ea-SNAPSHOT:compil
[INFO] |  +- javax.ws.rs:jsr311-api:jar:0.8:compile
[INFO] |  \- asm:asm:jar:3.1:compile
[INFO] \- com.sun.jersey:jersey-client:jar:1.9.1:test
[INFO]    \- com.sun.jersey:jersey-core:jar:1.9.1:test

重复项是一些从odata4j-jersey. 为了修复它们,您将在重复项上添加类似这样的内容:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
</project>
于 2013-01-24T14:03:13.773 回答
1

我得到了解决方案:

看来odata4j的两个依赖:

eclipselink-2.1.2
javax.persistence

有一些共同的课程。

因此,当排除一个或另一个依赖项时,问题就解决了。

似乎这实际上只是一个 android/adt 问题。通常,您不需要排除单个工件的依赖关系,对吗?

依赖项现在看起来像这样:

<dependency>
    <groupId>org.odata4j</groupId>
    <artifactId>odata4j-core</artifactId>
    <version>0.7.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
        </exclusion>
    </exclusions>
</dependency>

非常感谢 Mite 的有用提示。

问候,亚历克斯

于 2013-01-24T21:38:59.173 回答