问题描述
我下载了Google JSON模块a.k.a GSON。我在Windows系统上你能告诉我如何安装GSON模块吗?我将JAR提取到了我的类路径中的以下文件夹中: C:\程序文件\Java\jdk1 .6.0_07\\lib
..但是当我输入时:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
我仍然收到一个找不到模块的错误。
我在做什么错了? > JDK / lib
。您需要在类路径中使用 -cp
或 -classpath
参数。例如
java -cp。; / path / to / gson.jar com.example.MyClass
为了节省每次输入时间,请使用 .bat
文件执行它。
如果您实际上使用Eclipse之类的IDE,那么您也可以右键单击Java项目,选择 Build Path ,然后然后将其添加为新的 Library 。然后,Eclipse将自动将它放入编译时和运行时类路径中。
I downloaded the Google JSON module a.k.a GSON. I'm ona windows system Could you tell me how to install the GSON module? I extracted the JAR into the following folder which was in my classpath:
C:\Program Files\Java\jdk1.6.0_07\lib
..but when i type:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
I still get a module not found error.
What am I doing wrong?
Thanks.
- You should not extract the JAR.
- You should not put 3rd party libraries in
JDK/lib
.
You need to specify it in the classpath using -cp
or -classpath
argument. E.g.
java -cp .;/path/to/gson.jar com.example.MyClass
To save the time in typing it everytime, use a .bat
file to execute it.
If you're actually using an IDE like Eclipse, then you can also just rightclick the Java project, choose Build Path and then add it as new Library. Eclipse will then automatically take it in both the compiletime and runtime classpath.
这篇关于如何在Java中安装GSON模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!