Where do java packages live on a linux system? Package org.json does not exist Error using javac

dm03514 picture dm03514 · Feb 26, 2011 · Viewed 7k times · Source

I am trying to compile a library I wrote, using javac and I am getting the error: package org.json does not exist. My program includes org.json.JSONArray and org.json.JSONException.

I have this package installed on my computer because I have successfully compiled android apps that import org.json libraries. I'm pretty sure all I have to do is specify a -classpath but I have been unable to find where these files live on my system (ubuntu 10.10 64-bit sun-java6).

Having been unable to find these on my own system I downloaded the org.json files from here, but I was unable to compile them individually because they were co-dependent on each other.

So I have a couple questions:

  1. Does anyone know where the org.json package lives from android sdk install?
  2. Where might I find a tutorial explaining these basic concepts regarding compiling, and javac.

Answer

MeBigFatGuy picture MeBigFatGuy · Feb 26, 2011

Whatever external jars you need to compile with should be on the classpath when you compile. The most non-invasive way to do this is do add these items to the javac command line such as

javac -classpath /path/to/json.jar;. -g YourClass.java

or more likely if you use an IDE, add these jars to your referenced jars of the project in your IDE.

It usually isn't a good idea to pollute the global $CLASSPATH variable, as this then gets pulled in for everything you do with java, which may cause unintended conflicts.