Adding a build path variable in Eclipse

adding javabook.jar

The old way -- adding an external JAR file

In the first lab, we showed you how to add an external JAR file to a project's build path. That works fine, until you want to share your project (e.g. when you want to share it with me so I can grade it). When you add an external JAR file, you tell Eclipse where to find the JAR file on your computer. However, if you want to share the project, the person you share it with would need to have the JAR file stored in exactly the same place.

The better way -- adding a build path variable

Because Eclipse is designed for real programming, by real programming teams, it supports sharing projects. One way it does this is by making it possible to avoid hard-coding the full paths for the JAR files you are using. Instead, you can create a variable and add it to your project's build path. Since the specific value of the variable (the path to the actual JAR file) is not part of the project, but part of your Eclipse workspace, you can more easily share the project. The person you share with (me) will then simply give the variable a value in their workspace to tell Eclipse where to find their copy of the JAR file.

For example, you can say to use the javabook.jar library located at /Volumes/UnixFiles/csc150/workspace by creating a variable called "javabook library" whose value is "/Volumes/UnixFiles/csc150/workspace". You can then add this variable to your project's build path. The person you share with can then give a different value to specify where they have stored the JAR file.

How to add a variable

  1. Make sure you have javabook.jar. You can download it here.
  2. Open the Java Build Path property pane for your project (Project > Properties).
  3. Choose the Libraries tab of the build path pane.
  4. Click the Add Variable... button.
  5. You will be presented with a list of already declared variables. If the javabook variable is already there, and if it's value is correct, then select it and click OK. If not, continue to the next step.
  6. Click Configure Variables....
  7. A new window will appear. Click New to create a new variable. Define it:
    Name: javabook library
    Path: the path to your copy of javabook.jar
    Note: in order to make it easy for me to use your project, please be sure you use the exact variable name above (same spelling and spacing).
  8. Click OK to finish configuring variables. Click OK again to choose to add the javabook library variable to your project.