ashish Kumar
ashish Kumar

Reputation: 33

how to add json jar lib to java using environment variable

i have prepared a java file that uses Json library so i downloaded a JSON library from "http://code.google.com/p/json-simple/downloads/detail?name=json_simple-1.1-all.zip&can=2&q=" but very confuse where to place it, so that my java file can detect Json library.

I tried to place the lib "json_simple-1.1" inside "C:\Program Files\Java\jdk1.6.0_07\lib" but not working yet.

How can i solve the problem using environment variable or any other means where i don't need to set path on comman prompt?

Upvotes: 0

Views: 2113

Answers (3)

Ortwin Angermeier
Ortwin Angermeier

Reputation: 6203

Try the following:

set CLASSPATH=%CLASSPATH%;<path to libraries folder>

Upvotes: 0

amicngh
amicngh

Reputation: 7899

There are number of ways you can include jar file to run your program.

java -classpath "{yourpath}/json.jar:." my.package.Program
java -cp "{yourpath}/json.jar:." my.package.Program

Other way is to set env variable java.ext.dirs.

-Djava.ext.dirs=jarDirectory

Upvotes: 1

wrm
wrm

Reputation: 1908

You can put it beside your jar (in case you package your application into a jar) and add a link to it in your manifest, e.g.:

your jar contains a META-INF/MANIFEST.MF file which has (besides others) this entry:

Class-Path: json_simple-1.1.jar

More details here.

Upvotes: 0

Related Questions