Monday, June 30, 2014

Building json.org as a java library

If you've done any pure Java development in the recent years you've probably found the need to work with JSON objects. Lots of SDK's include their own JSON parser or include the json.org parser. But what about if you're writing POJO (plain old java objects) libraries?

Here's a real quick and simple way to get the json.org code and compile it into a reusable library.

First you need to download the source code.

Next you need to extract the source code:
$ unzip json.org

$ mkdir src

$ mv org src

After you've extracted the source you need to compile the json.org source:

$ mkdir -p bin/classes

$ javac -d bin/classes src/org/json/*.java

The final step is to create the org.json.jar

$ cd bin/classes

$ jar cvf org.json.jar .

You now have a library you can use for JSON parsing with a simple reference in your project.

No comments:

Post a Comment