Adding Gson to netbeans java project

眉间皱痕 提交于 2019-12-06 09:34:52

问题


I have downloaded gson.jar from its source.

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

However when i try to use

Gson gson = new Gson();

It complains that it cannot find symbol Gson.

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

Thanks for help!


回答1:


Go to Download Gson

There, access last Gson version:

You will see sth like this:

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

  • gson-2.8.0.jar (classpath)
  • gson-2.8.0-sources.jar (sources)
  • gson-2.8.0-javadoc.jar (javadoc)

Then, you have to create a library on 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

It should work now!




回答2:


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.



来源:https://stackoverflow.com/questions/41332506/adding-gson-to-netbeans-java-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!