0

I am in need of the json package, these are the imports i need to resolve:

    import org.json.simple.JSONObject;
//import net.sf.json.JSONObject;
class json
{
    public static void main(String[] args)
    {
        JSONObject obj=new JSONObject();
        obj.put("name","foo");
        obj.put("num",new Integer(100));
        obj.put("balance",new Integer(1000));
        obj.put("is_vip",new Boolean(true));
        System.out.print(obj);
    }
}

i have downloaded the json package (json-simple-1.1.1.jar) from google code. Now i don't know how to install it in my fedora 14. I am using java version 1.6.0_20. Is there any specific version of json that i could download for this java version?

I have tried to execute it using the command

java -jar json-simple-1.1.1.jar

but i got a message showing

"Failed to load Main-Class manifest attribute from json-simple-1.1.1.jar"

ambrosia1993
  • 245
  • 2
  • 5
  • 13

2 Answers2

0

You say you are running the application as

java json

Try specifying the jar in the classpath:

java -cp /path/to/json-simple-1.1.1.jar json

Where /path/to/json-simple-1.1.1.jar Is the path to the jar library

BackSlash
  • 21,927
  • 22
  • 96
  • 136
  • thank u but now i got an exception Exception in thread "main" java.lang.NoClassDefFoundError: json Caused by: java.lang.ClassNotFoundException: json at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: json. Program will exit. – ambrosia1993 Feb 14 '14 at 09:15
  • @user3184228 Can you update your question with the code you are trying to compile and run? – BackSlash Feb 14 '14 at 09:15
  • @user3184228 Are you running the command I wrote from the folder where `json.java` is? – BackSlash Feb 14 '14 at 09:20
  • yes both the code and the jar file are in the same folder – ambrosia1993 Feb 14 '14 at 09:31
0

i just used the export statement it helped me

[root@foss json]# export CLASSPATH=/root/Desktop/json-simple-1.1.1.jar:$CLASSPATH

ambrosia1993
  • 245
  • 2
  • 5
  • 13