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

查看:38
本文介绍了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,这意味着依赖项在运行时不存在.为此,您可以使用 provided 范围.更多关于 Apache 的 maven 依赖范围的信息 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天全站免登陆