tags:

views:

219

answers:

4

I am completely new to Java development so bear with me...

I have downloaded the Joda time library which consists of three files:

  • joda-time-1.6.jar
  • joda-time-1.6-javadoc.jar
  • joda-time-1.6-sources.jar

Firstly, how do I use this library in one of my own NetBeans projects?

Secondly, generally speaking, what is the distinction between the three files above? What do the labels 'javadoc' and 'sources' signify? How are these jars different from the 'joda-time-1.6.jar' library?

Many thanks for any help.

+7  A: 

You would add the JAR file to the Libraries in your project:

alt text

As for the different JARs,

  • joda-time-1.6.jar just contains the compiled classes (this is the JAR you need in order to use Joda in your project)
  • joda-time-1.6-javadoc.jar contains the documentation for all the classes
  • joda-time-1.6-sources.jar contains the source code for all the classes
Kaleb Brasee
+2  A: 

When you create a new project there is a library folder in the project viewer. Right click on that and pick the add jar file option. Once you add the joda-time-jar you can associate either the sources or the javadoc jar with that joda-time.jar. Associating the source or the java doc allows netbeans to provide intellisense.

  • Joda-time.jar contains the Joda library .class files.
  • joda-time-javadoc contains the javadoc html files that describe the library api.
  • joda-time-sources contains the actual java source files for the library.
ssteidl
Thanks, that's useful. Can you just tell me how to associate the documentation with the joda-time.jar?
MalcomTucker
+3  A: 

In addition to adding JARs or Folders directly to your project, you can add them to the Library and share them among multiple projects. From the Tools menu choose Libraries to get a dialog for adding libraries. Once added, they can be selected from the Add Library... context menu, as shown in Kaleb Brasee's asnswer. Note, for example, the additions of H2 Database, JFreeChart and JScience: NetBeans 6.7.1 Library Manager

trashgod
+2  A: 

There are many ways to use a .jar file in NetBeans. Kaleb and trashgod have covered two of them. The important thing to do is figure out which is right for you.

If you have a random jar file that has functionality that you want to use in your project, the 'Add Jar/Folder...' option can be a good choice. Your project will become dependent on that jar file. If you start to share the project with other folks, they will need to have that jar to compile the code.

When you add a jar file to the project, the NB Java editor will be able to take advantage of it and provide code completion (display method signatures in a popup that you can select).

Taking the extra time to create a Library for the Joda Time may be a better choice in this particular case. By creating a library, you can associate the javadoc with the functionality. This makes code completion in the NB editor even more useful, since NB will show you the javadoc associated with the method signatures that you can select. Good javadoc will help you decide which method is really the right one for you. You can also associate the source of the library with the jar. This becomes very useful when you start to debug code, since you will be able to 'step into' the library code. These are great additional features that are not supported by using the 'Add Jar/Folder...' option.

Creating a library does have some disadvantages, though...

Folks that want to compile your code would need to create a similar Library, which will be a bit more work.

vkraemer
One way we deal with that here is by checking in all of the Netbeans project information with the source code (next to the equivalent eclipse configuration). That way, we come as close as we can to producing a buildable configuration in the IDE immediately after checkout from SVN.
Bob Cross