GSON没有被导入maven项目 [英] GSON is not being imported into the maven pproject

查看:1374
本文介绍了GSON没有被导入maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有人可以指出我做错了什么吗?

$ b我得到以下错误 - 我在我的依赖项中添加了GSon
$ b



编辑:指定的依赖关系 -

 < dependency> 
< groupId> com.google.code.gson< / groupId>
< artifactId> gson< / artifactId>
< version> 1.7.1< / version>
< /依赖关系>

我在我的sevlet中使用以下代码 -

  JSONService json = new JSONService(); 
String json_output = json.makeLoginJSON(user);

makeLoginJSON ---

  public String makeLoginJSON(LoginDetails user){
String FinalJson = null;
Gson gson = new Gson();
FinalJson = gson.toJson(user);
返回FinalJson;


解决方案

Try:

 < dependency> 
< groupId> com.google.code.gson< / groupId>
< artifactId> gson< / artifactId>
< version> 2.1< / version>
< scope>提供< / scope>
< /依赖关系>

我编辑了我的评论并添加了范围。默认范围是 compile ,这意味着依赖项在运行时不存在。为此,您使用提供的范围。更多关于Apache的 Maven Dependencies简介



希望这可以解决您的问题。



PS:如果您要创建自己的存储库,还应该看看此处


I am getting the following error - I have added the GSon in my dependency -

Can someone point out what I am doing wrong?

Edit : dependency specified -

   <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>1.7.1</version>
    </dependency>

I am using the following code in my sevlet -

 JSONService json = new JSONService();
    String json_output = json.makeLoginJSON(user);

makeLoginJSON ---

   public String makeLoginJSON(LoginDetails user) {
    String FinalJson = null;
    Gson gson = new Gson();
    FinalJson = gson.toJson(user);      
    return FinalJson;       
}

解决方案

Try:

<dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
</dependency>

I have edited my comment and added the scope. The default scope is compile, meaning that the dependency is not present at runtime. For this, you use the provided scope. More about scopes in maven dependencies on Apache's Introduction to Maven Dependencies.

Hope this resolves your issue.

P.S.: if you are creating your own repository, you should also take a look here.

这篇关于GSON没有被导入maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆