英文:
How do I add a jar file to import the class?
问题
我下载了json-20200518.jar(从这里:https://mvnrepository.com/artifact/org.json/json/20200518),并将其放在我的bin文件夹中(与javac.exe所在的文件夹相同),该文件夹已添加到我的PATH变量中。
我的client.java文件内容如下:
import org.json.simple.JSONObject;
在命令提示符中,我运行了以下命令:
javac -cp json-20200518.jar client.java
然后我得到了这个错误:
client.java:3: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
我需要怎么处理这个jar文件才能使它正常工作?
英文:
I downloaded json-20200518.jar (from here: https://mvnrepository.com/artifact/org.json/json/20200518), and put it in my bin folder (the same folder where I have javac.exe) which is added to my PATH variable.
My client.java file has:
import org.json.simple.JSONObject;
In cmd, I run:
javac -cp json-20200518.jar client.java
And I get this error:
client.java:3: error: package org.json.simple does not exist
import org.json.simple.JSONObject;
What do I have to do with the jar file to make it work?
答案1
得分: 1
在指定的Maven Jar文件链接中,JSONObject
类的包结构是org.json.JSONObject
。
尝试将包名从org.json.simple.JSONObject
更改为org.json.JSONObject
,它将成功编译。
英文:
In the specified maven jar file link, the package structure for JSONObject
class is org.json.JSONObject
.
Try to change the package name from org.json.simple.JSONObject
to org.json.JSONObject
and it will compile successfully.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论