How do I install the GSON module in Java
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.开发者_Python百科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.
精彩评论