Mridang Agarwalla
Mridang Agarwalla

Reputation: 44998

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.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.

Upvotes: 16

Views: 52644

Answers (1)

BalusC
BalusC

Reputation: 1108772

  1. You should not extract the JAR.
  2. 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.

Upvotes: 14

Related Questions