当前位置: 动力学知识库 > 问答 > 编程问答 >

java - package com.google.gson does not exist. build failure error in spring GSON

问题描述:

I am trying to pass a list of objects to ajax from my spring MVC controller. I'm using GSON to convert the list and parse it after it's been received in the ajax call.

It works fine. But when I try build my project I get the following error.

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project SkillSet: Compilation failure: Compilation failure:

[ERROR] /C:/Users/muralil/SkillSet2/SkillSet - Copy/src/main/java/com/skillset/controller/EmployeeController.java:[25,23] package com.google.gson does not exist

[ERROR] /C:/Users/muralil/SkillSet2/SkillSet - Copy/src/main/java/com/skillset/controller/EmployeeController.java:[154,17] cannot find symbol

[ERROR] symbol: class Gson

[ERROR] location: class com.skillset.controller.EmployeeController

[ERROR] /C:/Users/muralil/SkillSet2/SkillSet - Copy/src/main/java/com/skillset/controller/EmployeeController.java:[154,31] cannot find symbol

[ERROR] symbol: class Gson

[ERROR] location: class com.skillset.controller.EmployeeController

I have included the gson jar file in the project's build path and also the lib folder inside webapps. I have no clue why there is a build failure. Also when I go ahead and start the server the code works perfectly fine!

I tried adding the following dependency to my pom.xml with no luck

<dependency>

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

<artifactId>gson</artifactId>

<version>2.2.4</version>

<scope>compile</scope>

</dependency>

I got the following error

Could not resolve dependencies for project SkillSet:SkillSet:war:0.0.1-SNAPSHOT: Failed to collect dependencies at com.google.code.gson:gson:jar:2.2.4: Failed to read artifact descriptor for com.google.code.gson:gson:jar:2.2.4: Could not transfer artifact com.google.code.gson:gson:pom:2.2.4 from/to central (repo.maven.apache.org/maven2): Not authorized by proxy , ReasonPhrase:Proxy Authentication Required. -> [Help 1] [ERROR] –

I fixed it by going to the settings.xml file in your maven folder and setting proxy settings :) Now my build is successfully completed

分享给朋友:
您可能感兴趣的文章:
随机阅读: