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

图片描述

<?xml version="1.0" encoding="UTF-8"?>

<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>activemq.apache</groupId>

<artifactId>graduation03</artifactId>

<version>1.0-SNAPSHOT</version>

<dependencies>

<!-- webSocket -->

<dependency>

<groupId>javax</groupId>

<artifactId>javaee-api</artifactId>

<version>7.0</version>

</dependency>

<!-- MySql 5.5 Connector -->

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.45</version>

</dependency>

<!-- config -->

<dependency>

<groupId>com.typesafe</groupId>

<artifactId>config</artifactId>

</dependency>

<dependency>

<groupId>com.github.racc</groupId>

<artifactId>typesafeconfig-guice</artifactId>

</dependency>

<dependency>

<groupId>org.fusesource.stompjms</groupId>

<artifactId>stompjms-client</artifactId>

<version>1.18</version>

</dependency>

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>fastjson</artifactId>

<version>1.2.31</version>

</dependency>

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.1.0</version>

</dependency>

<!-- https://mvnrepository.com/artifact/jstl/jstl -->

<dependency>

<groupId>jstl</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

</dependency>

<dependency>

<groupId>com.google.code.gson</groupId>

<artifactId>gson</artifactId>

<version>2.3.1</version>

</dependency>

</dependencies>

</project>

回答:

看最后一个报错,ClassNotFoundException,找不到包。

可能是你修改了 pom.xml 并没有令其生效,那么右击项目 -> maven -> update..

回答:

或者可以看下你的本地库里有没有对应的jar

回答:

如果是eclipse可能会出现这个问题,idea你修改pom文件是会提醒你更新的。
建议在命令行下重新构建项目,如果是eclipse 建议使用maven插件构建eclipse配置文件。

mvn clean install 

mvn eclipse:eclipse

回答:

检查一下有没有gson.jar这个包?

以上是 java.lang.NoClassDefFoundError: com/google/gson/Gson 的全部内容, 来源链接: utcz.com/p/171990.html

回到顶部