将 Gson 添加到 netbeans java 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41332506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:49:17  来源:igfitidea点击:

Adding Gson to netbeans java project

javanetbeansgsonnetbeans-8

提问by Dingo

I have downloaded gson.jar from its source.

我已经从它的源代码下载了 gson.jar。

Right-clicked at libraries folder -> add new -> add jar -> gson.jar

右键单击库文件夹 -> 添加新 -> 添加 jar -> gson.jar

However when i try to use

但是当我尝试使用

Gson gson = new Gson();

It complains that it cannot find symbol Gson.

它抱怨找不到符号 Gson。

What is the right way how to add gson to the project? I am not using maven

如何将 gson 添加到项目中的正确方法是什么?我没有使用 maven

Thanks for help!

感谢帮助!

回答by Loaderon

Go to Download Gson

下载 Gson

There, access last Gson version:

在那里,访问最新的 Gson 版本:

enter image description here

在此处输入图片说明

You will see sth like this:

你会看到这样的:

enter image description here

在此处输入图片说明

In order to import Gson using netbeans you will need to download 3 files from here:

为了使用 netbeans 导入 Gson,您需要从这里下载 3 个文件:

  • gson-2.8.0.jar (classpath)
  • gson-2.8.0-sources.jar (sources)
  • gson-2.8.0-javadoc.jar (javadoc)
  • gson-2.8.0.jar(类路径)
  • gson-2.8.0-sources.jar(来源)
  • gson-2.8.0-javadoc.jar (javadoc)

Then, you have to create a library on netbeans:

然后,您必须在 netbeans 上创建一个库:

  • Right click on Libraries (inside the project in which you want to add Gson)
  • Properties
  • In categories: Libraries
  • Add Library (write a name, e.g.: Gson)
  • You have to import the right file in each of the tabs: classpath, sources, javadoc
  • 右键单击库(在要添加 Gson 的项目中)
  • 特性
  • 在类别中:图书馆
  • 添加库(写一个名字,例如:Gson)
  • 您必须在每个选项卡中导入正确的文件:classpath、sources、javadoc

enter image description here

在此处输入图片说明

It should work now!

现在应该可以了!

回答by user3238382

I am new to this. I used the same method of import that you used. It told me that it cannot find symbol Gson so I used CTRL+SHIFT+I to import correct library for gson and now everything is ok. You can also add this import statement import com.google.gson.Gson; to the top of the page. I do apologize about the non-technical formatting of this paragraph.

我是新来的。我使用了与您使用的相同的导入方法。它告诉我它找不到符号 Gson,所以我使用 CTRL+SHIFT+I 为 gson 导入正确的库,现在一切正常。你也可以添加这个import语句import com.google.gson.Gson; 到页面顶部。对于本段的非技术格式,我深表歉意。