GSON未导入到Maven项目中 [英] GSON is not being imported into the maven project

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

问题描述

我遇到以下错误-我在依赖项中添加了GSon-

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

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

Can someone point out what I am doing wrong?

指定依赖项-

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

我在sevlet中使用以下代码-

I am using the following code in my sevlet -

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

makeLoginJSON ---

makeLoginJSON ---

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

推荐答案

尝试:

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

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

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.

PS:如果您正在创建自己的存储库,还应该看看这里.

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

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

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