如何添加一个 JAR 文件以导入这个类?

huangapple go评论74阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月6日 02:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63757365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定