2012-05-25 26 views
0

我注意到一個奇怪的問題。我能夠使用Junit運行我的測試用例,但是當我使用maven運行時,其中一個測試用例失敗。抱怨Gson class def沒有找到。java.lang.NoClassDefFoundError:com/google/gson/Gson

我能看到GSON罐子在Maven依賴。

所以我懷疑classpath是不包括Gson的。所以我用-X運行maven並注意到一些線索。

[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository) 
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date. 
[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository) 
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date. 
[WARNING] The POM for com.example.libraries:Symbology:jar:1.0.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for com.example.libraries:Symbology:1.0.0-SNAPSHOT 
[ERROR] 'dependencies.dependency.artifactId' for ::jar is missing. @ 
[ERROR] 'dependencies.dependency.groupId' for ::jar is missing. @ 

我有一個項目,這取決於Symbology項目,這反過來使用Gson。 但是現在從這個日誌中我看到傳遞依賴並沒有包含在內。所以Gson類沒有被發現。

這裏是符號POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.example.libraries</groupId> 
<artifactId>Symbology</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>Symbology</name> 
<url>http://maven.apache.org</url> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
     <version>2.1</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
    </dependency> 
</dependencies> 

這裏是我的項目中的哪一個調用符號的雙響炮:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.example.libraries</groupId> 
<artifactId>FGF</artifactId> 
<version>1.0.0-SNAPSHOT</version> 
<packaging>jar</packaging> 
<distributionManagement> 
    <snapshotRepository> 
     <id>example.com</id> 
     <name>example.com-snapshots</name> 
     <url>http://example/artifactory/libs-snapshots-local</url> 
    </snapshotRepository> 
</distributionManagement> 

<name>FGF</name> 
<url>http://maven.apache.org</url> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<dependencies> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
    </dependency> 
    <dependency> 
     <groupId>com.example.libraries</groupId> 
     <artifactId>Category</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>com.example.libraries</groupId> 
     <artifactId>Time</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>com.example.libraries</groupId> 
     <artifactId>Display</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
    </dependency> 
    **<dependency> 
     <groupId>com.example.libraries</groupId> 
     <artifactId>Symbology</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
    </dependency>** 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>3.2.0.BUILD-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.directory.studio</groupId> 
     <artifactId>org.apache.commons.lang</artifactId> 
     <version>2.6</version> 
    </dependency>  

</dependencies> 

+1

沒有嘗試指定與的GSON依賴編譯? – sfat

+1

這些星號是故意寫的嗎? – Luciano

+0

是的。它們並不存在於原來的POM – javaMan

回答

1

想通了最後後的整合問題花費很多時間。

的問題是,當我推符號神器資料庫,能夠不推POM到庫中。因此,當我使用符號學工件作爲依賴項時,我的項目無法知道傳遞依賴項是什麼。

所以我把我的聚甲醛到存儲庫罐子一起,現在是能夠得到所有的依賴。

HURRAYYYYYYYYYYYYYYYYY !!!!!!!!!!!!!!!!!!