Reputation: 291
I try compile following code (file Main.java):
import org.json.simple.JSONObject;
public class Main {
public static void main (String[] args) {
JSONObject obj = new JSONObject();
obj.put("name", "foo");
obj.put("num", new Integer(100));
obj.put("balance", new Double(1000.21));
obj.put("is_vip", new Boolean(true));
System.out.print(obj);
}
}
json-simple also included (stored at ./lib/)
javac Main.java
java -cp .:lib/json-simple-1.1.1.jar Main
And i got:
error: package org.json.simple does not exist
cannot find symbol JSONObject obj = new JSONObject();
What i doing wrong?
P.s. i'm using:
Ubuntu 14.04
Java(TM) SE Runtime Environment (build 1.7.0_04-b20) Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
I'm not using any IDE
Update:
Current directory:
/home/user/helloworld/
json-simple placed to directory:
/home/user/helloworld/lib/
Upvotes: 0
Views: 4141
Reputation: 16545
You need to give javac
the classpath so it can compile the Java source into class files.
Use:
javac -cp .:lib/json-simple-1.1.1.jar Main.java
Note that you still need to supply the json-simple
jar on the classpath when you run it too (i.e. like you have been doing).
Upvotes: 2