eclipse 添加JSON类文件夹并在Java和Eclipse中作为IDE导入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5143699/
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
Add JSON class folder and import in Java and Eclipse as IDE
提问by einstein
I'm new to Java and have searched for quite a time now on the internet to a solution to my problem. I'm trying to add the JSON classes folder to my web app. The folder for JSON classes can be retrieved from this link: http://www.json.org/java/. What I did is copied the folder to my WEB-INF/lib folder and added that folder to my classpath by rightclick on Libraries -> Build Path -> Configure Build Path -> Add Class Folder. Ok so far so good! Btw, is this the right procedure for adding class folders? But what shall I type in a new Java class?
我是 Java 新手,现在已经在互联网上搜索了很长时间来解决我的问题。我正在尝试将 JSON 类文件夹添加到我的网络应用程序。可以从此链接检索 JSON 类的文件夹:http: //www.json.org/java/。我所做的是将该文件夹复制到我的 WEB-INF/lib 文件夹,并通过右键单击库 -> 构建路径 -> 配置构建路径 -> 添加类文件夹将该文件夹添加到我的类路径中。到目前为止一切顺利!顺便说一句,这是添加类文件夹的正确程序吗?但是我应该在一个新的 Java 类中输入什么?
I have tried import JSONArray
, but it is not working. Could you please give the right syntax for importing the JSON classes?
我试过了import JSONArray
,但它不起作用。您能否提供导入 JSON 类的正确语法?
回答by Jeremy
You need to use the fully-qualified class name, which includes the package:
您需要使用完全限定的类名,其中包括包:
import org.json.JSONArray;
(And yes, that is the correct way to add classes/jars to your project's classpath in Eclipse.)
(是的,这是在 Eclipse 中将类/jar 添加到项目类路径的正确方法。)
回答by justLearning
If you wana to use servlets in tomcat you also have to copy the org.json.jar to lib in tomcat folder. If not eclipse will not give you any error but tomcat will.
如果您想在 tomcat 中使用 servlet,您还必须将 org.json.jar 复制到 tomcat 文件夹中的 lib。如果不是 eclipse 不会给你任何错误,但 tomcat 会。