Introduction
In this tip I will be focusing on how to create a user library in Eclipse. User libraries help you to quickly setup a new project with a library pack you got from some source. Examples of library packs are The Lightweight Java Gaming Library (LWJGL), ANother Tool for Language Recognition (ANTLR), and Jython.
Difficulty: Easy. This is a fairly easy process, and is actually easier (as well as more robust) than other methods for setting up eclipse to use a library. For the purposes of this tip, I'll be focusing on doing this process with LWJGL, but the same process can be applied to any library (even ones you make yourself).
Basic Procedure
A. Go into the Eclipse preferences > Java > User Libraries. Click on "New.."
user_libraries01.jpg
B. Choose a name for your user library. Unless you know what you're doing, I suggest leaving the "System Library" checkbox unchecked. Push "OK".
add_library2.jpg
user_libraries02.png
C. Your library should now show up in the list of user libraries. Now we need to add the jar files and/or source/javadoc associated with this library. Select your library and click "Add JARs...". Navigate to the location where you put the library. As a general rule, you SHOULD NOT put these JAR files into the same directory as the JRE or JDK! Normally I create a directory for all my Java executables and libraries, with a sub-directory for the JRE install, a sub-directory of the JDK install, and other sub-directories for any libraries you want).
user_libraries03.jpg
library_path.jpg
library_jars.jpg
D. For each JAR file, there are 4 additional parameters you can attach to the JAR: Source location, Javadoc location, Native library location, and access rules. For this tutorial I will ignore the last parameter. The source and Javadoc locations are always option, however I would strongly recommend including the Javadoc if it's available. The Native library location is the location of an JNI libraries used by that JAR. This is not an optional field, and must be included if the JAR requires one (see the library documentation).
library_jars2.png
Attaching Source location
This will allow you to step into the library's source code when you're debugging. In general, you won't need to do this (unless it's your library, or you're debugging the library).
E. Select "Source attachment" for a JAR, and click "Edit...".
source01.jpg
F. Choose a valid path to the location of the source for that JAR. Click "OK" when done.
source02.png
Attaching Javadoc location
This allows Eclipse to give you helpful Javadoc pop-ups when you try to use classes/members of the the Jar. I would highly suggest you add Javadocs for your libraries.
G. Select "Javadoc location" for a JAR, and click "Edit...".
H. You have a few options for choosing where the Javadoc is located. If the library has online Javadoc, you can even reference that. Below are screenshots of what these paths might look like for both local Javadoc and online Javadoc.
local_javadoc.jpg
online_javadoc.jpg
Attaching Native Library Location
I. Select "Native Library Location" and click "Edit...".
J. Enter a valid path for the native library location. Click "OK"
native_library.png
Using a User Library
Now that you have the user library all setup, you shouldn't need to touch it ever again (unless you're updating the library). All you need to do is tell eclipse that you want to include that library into the build path. This can be done either when you first create the project, or can be done after you create the project.
Modifying build path on New Project
1. Create a new Java Project. Enter in the name of the project and instead of clicking finish, click "Next>".
2. Click on the "Libraries" tab and choose "Add Library..."
add_library.jpg
3. Choose "User Library" and click "Next>"
add_library2.jpg
4. Check the libraries you want to use and click OK.
add_library3.jpg
5. Finish creating your Java project by clicking "Finish"
Modifying the build path on an existing project
1. Right click on the project in question and choose "Build Path" > "Add Libraries...". Follow steps 3 and 4 in the section above to add the library(s) to your project.
add_library4.jpg
Conclusion
Hopefully this will simplify the process of using external libraries for your projects. This method makes it extremely easy for you to manage a specific library and helps you maintain all your project libraries in one convenient location.
Happy Coding