java.lang.NoClassDefFoundError:com/google/gson/gson

java.lang.NoClassDefFoundError:com/google/gson/gson,java,eclipse,spring,maven,junit,Java,Eclipse,Spring,Maven,Junit,我注意到一个奇怪的问题。我可以使用Junit运行我的测试用例,但是当我使用maven运行时,其中一个测试用例失败了。它正在抱怨找不到Gson class def 我能够在Maven依赖项中看到Gson jar 所以我怀疑classpath不包括Gson。所以我用-X运行maven,发现了一些线索 [DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in

我注意到一个奇怪的问题。我可以使用Junit运行我的测试用例,但是当我使用maven运行时,其中一个测试用例失败了。它正在抱怨找不到Gson class def

我能够在Maven依赖项中看到Gson jar

所以我怀疑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>

4.0.0
com.example.libraries
符号学
1.0.0-SNAPSHOT
罐子
符号学
http://maven.apache.org
UTF-8
朱尼特
朱尼特
4.10
测试
com.google.code.gson
格森
2.1
log4j
log4j
1.2.16

这是我的项目的Pom,它叫做符号学:

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>
xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.example.libraries
FGF
1.0.0-SNAPSHOT
罐子
example.com
example.com-snapshots
http://example/artifactory/libs-snapshots-local
FGF
http://maven.apache.org
UTF-8
朱尼特
朱尼特
4.10
测试
log4j
log4j
1.2.16
com.example.libraries
类别
1.0.0-SNAPSHOT
com.example.libraries
时间
1.0.0-SNAPSHOT
com.example.libraries
展示
1.0.0-SNAPSHOT
**
com.example.libraries
符号学
1.0.0-SNAPSHOT
**
org.springframework
spring上下文
3.2.0.1构建快照
cglib
cglib
2.2.2
org.apache.directory.studio
org.apache.commons.lang
2.6

花了很多时间,终于解决了这个问题

问题是,当我将符号工件推送到存储库时,它并没有将pom推送到存储库中。因此,当我使用符号工件作为依赖项时,我的项目无法知道什么是可传递依赖项

所以我把pom和jar一起推到了存储库中,现在它能够获得所有依赖项


万岁

您是否尝试在编译时指定gson依赖项?这些星号是故意写的吗?是的。它们没有原件POM@AndreiSfat我将试一试,看看这些是否是您的pom.xml文件,它们是无效的。他们是否缺少项目所需的结束标记?