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

编程入门 行业动态 更新时间:2024-10-26 01:16:55
本文介绍了java.lang.NoClassDefFoundError:com / google / gson / Gson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我注意到一个奇怪的问题。我可以使用Junit运行我的测试用例,但是当我使用maven运行时测试用例之一是失败的。它是抱怨Gson类def没有找到。

我可以看到Maven依赖关系中的Gson jar。

所以我怀疑classpath不包括Gson。所以我用-X运行maven,并注意到一些线索。

[DEBUG]找不到元数据com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml在本地(C:\Users\ra\m2\repository) [DEBUG]跳过远程更新检查com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml,本地缓存的元数据是最新的。 [DEBUG]找不到元数据com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml在本地(C:\Users\ra\m2\repository) [DEBUG]跳过远程更新检查com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml,本地缓存的元数据是最新的。 [警告] com.example.libraries的POM:符号学:jar:1.0.0-SNAPSHOT无效,传递依赖(如果有)不可用:在构建com的有效模型时遇到2个问题.example.libraries:符号学:1.0.0-SNAPSHOT [ERROR]'dependencies.dependency.artifactId'for :: jar缺少。 @ [ERROR]'dependencies.dependency.groupId'for :: jar缺少。 @

我有一个依赖于Symbology项目的项目,反过来又使用Gson。 但现在从这个日志我看到传递依赖没有被包含。所以没有找到Gson类。

这里是符号学pom:

< project xmlns = maven.apache/POM/4.0.0xmlns:xsi =www.w3/2001/XMLSchema-instance xsi:schemaLocation =http:/ /maven.apache/POM/4.0.0 maven.apache/xsd/maven-4.0.0.xsd\"> < modelVersion> 4.0.0< / modelVersion> < groupId> com.example.libraries< / groupId> < artifactId>符号学< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < packaging> jar< / packaging> < name>符号学< / name> < url> http://maven.apache< / url> < properties> < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding> < / properties> <依赖关系> <依赖关系> < groupId> junit< / groupId> < artifactId> junit< / artifactId> < version> 4.10< / version> < scope> test< / scope> < / dependency> <依赖关系> < groupId> com.google.code.gson< / groupId> < artifactId> gson< / artifactId> < version> 2.1< / version> < / dependency> <依赖关系> < groupId> log4j< / groupId> < artifactId> log4j< / artifactId> < version> 1.2.16< / version> < / dependency> < / dependencies>

这是我的Pom正在调用symbology的项目:

xsi:schemaLocation =maven.apache/POM/4.0.0 maven.apache/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< / id> < name> example-snapshots< / name> < url> http:// example / artifactory / libs-snapshots-local< / url> < / snapshotRepository> < / distributionManagement> < name> FGF< / name> < url> http://maven.apache< / url> < properties> < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding> < / properties> <依赖关系> <依赖关系> < groupId> junit< / groupId> < artifactId> junit< / artifactId> < version> 4.10< / version> < scope> test< / scope> < / dependency> <依赖关系> < groupId> log4j< / groupId> < artifactId> log4j< / artifactId> < version> 1.2.16< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>类别< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>时间< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>显示< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> **< dependency> < groupId> com.example.libraries< / groupId> < artifactId>符号学< / 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> <依赖关系> < groupId> cglib< / groupId> < artifactId> cglib< / artifactId> < version> 2.2.2< / version> < / dependency> <依赖关系> < groupId> org.apache.directory.studio< / groupId> < artifactId> org.apachemons.lang< / artifactId> < version> 2.6< / version> < / dependency> < / dependencies>

解决方案

问题是当我将符号系统工件推送到存储库时,它不会将pom推入存储库。所以当我使用符号系统工件作为依赖项时,我的项目无法知道什么是传递依赖关系。

所以我把我的pom和jar一起推入存储库,现在它能够获得所有的依赖。

I noticed a strange problem. I am able to run my test cases using Junit but when I am running using maven One of the test case is failing. It is complaining that Gson class def is not found.

I am able to see the Gson jar in Maven dependencies.

So I doubted that classpath is not including the Gson. So I ran maven with -X and noticed some clues.

[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. @

I have a project which depends on Symbology project and this in turn uses Gson. But now from this log I am seeing transitive dependencies are not getting included. So Gson class is not being found.

Here is the Symbology pom:

<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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>maven.apache</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>

Here is the Pom of my project which is calling symbology :

xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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</id> <name>example-snapshots</name> <url>example/artifactory/libs-snapshots-local</url> </snapshotRepository> </distributionManagement> <name>FGF</name> <url>maven.apache</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.apachemons.lang</artifactId> <version>2.6</version> </dependency> </dependencies>

解决方案

Figured Out the Problem Finally after spending lot of time.

The problem is when I am pushing the symbology artifact to repository it is not pushing the pom into repository. So when I am using the symbology artifact as dependency my project is not able to know what are the transitive dependencies.

So I pushed my pom into repository along with jar and now it is able to get all the dependencies.

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

更多推荐

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

本文发布于:2023-05-25 10:52:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/226585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NoClassDefFoundError   lang   java   Gson   gson

发布评论

评论列表 (有 0 条评论)

最近发表

草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

热门文章

标签列表