简体   繁体   English

eclipse中无法识别jar文件

[英]jar file not recognized in eclipse

I needed a JSON API for Java and this seemed to be the most popular: 我需要用于Java的JSON API,这似乎是最受欢迎的:

https://github.com/douglascrockford/JSON-java https://github.com/douglascrockford/JSON-java

I downloaded the zip from github and the directory structure looks like this: 我从github下载了zip文件,目录结构如下所示:

$ ls
CDL.java          JSONArray.java      JSONString.java   README
Cookie.java       JSONException.java  JSONTokener.java  XML.java
CookieList.java   JSONML.java         JSONWriter.java   XMLTokener.java
HTTP.java         JSONObject.java     Kim.java          zip
HTTPTokener.java  JSONStringer.java   Property.java

I want to use this JSON API in my java 8 project in eclipse so I create a jar out of it: 我想在Eclipse的Java 8项目中使用此JSON API,因此我用它创建了一个jar:

$ jar cf json-java.jar *.java zip

Then I right clicked on project, selected build path > Configure Build Path > Add External Jars and then select the json-java.jar created above. 然后我右键单击项目,选择构建路径>配置构建路径>添加外部Jar,然后选择上面创建的json-java.jar。

Problem is when I try to use the following in the project: 问题是当我尝试在项目中使用以下内容时:

import org.json.JSONObject;

It gives me the error "The import org.json cannot be resolved", so I look in "Referenced Libraries and I notice the json-java.jar doesn't contain any class files or anything. It seems that it didn't import the jar properly: 它给我错误“无法解析导入org.json”,因此我在“参考库”中查找,我注意到json-java.jar不包含任何类文件或任何内容。似乎它没有导入罐子正确:

在此处输入图片说明

Any idea what I might be doing wrong? 知道我做错了什么吗?

Download the ZIP file from here . 此处下载ZIP文件。 and extract it to get the Jar. 并将其提取以获取Jar。

To add this Jar to your build path, 要将这个Jar添加到您的构建路径中,

Right click the Project > Build Path > Configure build path > Select Libraries tab > Click Add External Libraries > Select the Jar file Download 右键单击项目>构建路径>配置构建路径>选择库选项卡>单击添加外部库>选择Jar文件下载

What you did was, put all the source files into a jar file. 您要做的是,将所有源文件放入一个jar文件中。

That is not gonna work. 那是行不通的。 You need to compile the java into class files and then put those in your jar file. 您需要将Java编译为类文件,然后将其放入jar文件中。

Alternatively, you can download the binary jar from the following location and use that instead. 或者,您可以从以下位置下载二进制jar,然后改用它。

http://mvnrepository.com/artifact/org.json/json http://mvnrepository.com/artifact/org.json/json

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

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