0

I am a crazy Java beginner, FYI.

I want to compile a program (actually to answer an SO question) that uses the org.json package in these files: http://json.org/java/

I created a basic Java application in NetBeans, but how do I get these to be class files that my main class recognizes, and that they recognize each other. Do I need to jar them somehow and put them in the project's classpath? Can I just slap them in my src file along with the main class?

danieltalsky
  • 7,752
  • 5
  • 39
  • 60

2 Answers2

2

You can create a jar with them and add it to the classpath.

You can also put them in the src folder, but you need to honour the directory structure. This means that the files should be placed in a folder like this:

src/org/json/
kgiannakakis
  • 103,016
  • 27
  • 158
  • 194
2

If you don't plan of forking and modifying the org.json package, it is better to use it as a jar. The easiest way to add it to the classpath with netbeans:

  1. Download the jar in a dir outside the project.
  2. Tools > Libraries > New library...
  3. Fill the entries correctly, add the javadoc and the source if you have it.
  4. Right-click on your project and go to the properties item.
  5. Library > Add library...
  6. Choose the lib from the list.
paradigmatic
  • 40,153
  • 18
  • 88
  • 147
  • Thanks, that's useful, but the files are provided as .java source only, so I'd need to... download them to a separate directory and MAKE a jar file of them? – danieltalsky Dec 02 '09 at 11:07
  • When you add the library, you can also import a folder full of classes. Inside this folder you have to reproduce the package hierarchy using folders. – paradigmatic Dec 02 '09 at 11:17