views:

78

answers:

2

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?

Someone point me in the right direction?

+2  A: 

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
ok, putting the source files there makes a lot of the red !'s go away, but when I try to include org.json;I still get "package org does not exist".
danieltalsky
Maybe if you can tell us the overall netbeans project structure to help us figure out the problem.
DJ
Press Ctrl+Shift+I and let Netbeans do the importing for you.
kgiannakakis
+2  A: 

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
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
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