简体   繁体   English

将Gson添加到netbeans java项目中

[英]Adding Gson to netbeans java project

I have downloaded gson.jar from its source. 我从它的源代码下载了gson.jar。

Right-clicked at libraries folder -> add new -> add jar -> gson.jar 右键单击libraries文件夹 - >添加新 - >添加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? 如何将gson添加到项目中的正确方法是什么? I am not using maven 我不是在使用maven

Thanks for help! 感谢帮助!

Go to Download Gson 转到下载Gson

There, access last Gson version: 在那里,访问最后的Gson版本:

在此输入图像描述

You will see sth like this: 你会看到这样的:

在此输入图像描述

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.jar(classpath)
  • gson-2.8.0-sources.jar (sources) gson-2.8.0-sources.jar(来源)
  • gson-2.8.0-javadoc.jar (javadoc) 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) 右键单击Libraries(在要添加Gson的项目中)
  • Properties 属性
  • In categories: Libraries 类别:图书馆
  • Add Library (write a name, eg: Gson) 添加库(写一个名字,例如:Gson)
  • You have to import the right file in each of the tabs: classpath, sources, javadoc 您必须在每个选项卡中导入正确的文件:classpath,sources,javadoc

在此输入图像描述

It should work now! 它现在应该工作!

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. 它告诉我,它找不到符号Gson所以我使用CTRL + SHIFT + I为gson导入正确的库,现在一切正常。 You can also add this import statement import com.google.gson.Gson; 您还可以添加此导入语句import com.google.gson.Gson; to the top of the page. 到页面顶部。 I do apologize about the non-technical formatting of this paragraph. 我为本段的非技术格式道歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM