For BlueJ users: how to make packages; how to use javadoc and jar

I. Constructing packages within BlueJ

If you use BlueJ to do your CIS300 assignments, please be aware that BlueJ requires a specific procedure for constructing and using packages.

Downloads

First, please ensure that you are using BlueJ Version 1.1.4 or newer. This also requires that you install the ``Java 2 Standard Edition,'' JDK 1.3 or newer, also. See http://www.bluej.org/download/download.html to download BlueJ, and see http://java.sun.com/j2se to download the JDK.

Constructing Packages

Say that you want to use BlueJ to construct a folder, Assign1, that contains a package named P. Within package P you wish to insert a class, C.java. Here is what you do:

  1. Click on the Project menu, and click on its New Project menu item. A file dialog appears that asks you the name of the folder you wish to create---type Assign1 and press the create button.

    Important: You can tell BlueJ where on your disk you wish to create the folder, Assign1. Remember where you created it --- this will make your life easier when it is time to submit your work for grading.

  2. As a result of the previous step, BlueJ creates a new folder named Assign1, and it opens a new window presenting the folder to you. (Alas, in BlueJ, a folder (directory) is called a ``project''!)

    Now, we are ready to create the package, P: Within the Assign1 window, click on the Edit menu, and click on its New Package menu item. A dialog appears and asks you for the name of the package---type P and press OK.

  3. As a result of the previous step, a folder named P has been created inside folder Assign1.
  4. Now you are ready to include class C within package P. You can do this two ways:

    1. Write it from scratch:

    At this point, you can edit and compile the various java-files as usual.

    2. Copy it from somewhere else:

    Say that class C is already written and saved as the file, C.java, in another folder. You can copy it into the package by

    Note: Unfortunately, I cannot locate a simple shortcut that will let you copy an entire folder of files into a BlueJ-created package. For now, you are stuck copying classes one at a time. (With a bit of effort, you can find a hack.)

II. Using javadoc and jar

The latest version of BlueJ lets you start javadoc: Open a package, click on the Tools menu, and select the Project Documentation menu item. This runs javadoc on the opened package and constructs a new folder with the documentation, named doc, at the same folder where the package itself lives.

Important: There is no guarantee that BlueJ's implementation of javadoc works correctly. If you receive an error message from BlueJ, then you must generate your documentation by starting javadoc from the command window --- see below.

We use the jar program to prepare a CIS300 assignment for submission. At the time of writing, I do not know where to locate jar within BlueJ. Fortunately, a separate copy of jar is included with every installed copy of Java---see below for instructions.

How to use javadoc from the command window:

To use javadoc, try the following:

  1. Open a command window (a ``DOS window'').
  2. Do cd to the directory where Assign1 lives.
  3. Do cd Assign1
  4. To generate the API web-pages for all the classes in package P, type javadoc -classpath . P
If this does not operate correctly, see the note below.

How to use jar from the command window:

To use jar, try the following:

  1. Open a command window (a ``DOS window'').
  2. Do cd to the directory where Assign1 lives.
  3. Type jar c Assign1 > Assign1.jar
If this does not operate correctly, see the note below.

What if javadoc and jar don't work?

This is because your OS's ``path'' variable is not set to locate the javadoc and jar programs. To repair this, do the following:

Now, we wish to add the directory path, C:\jdk1.3.1_02\bin, to the end of the OS's ``path'' variable.

At this point, you are ready to use javadoc and jar from the MS-DOS window.

What if I cannot reset the path variable?

Here is a hack that always works: Within a command window, prefix the jar command with its directory path, like this:
C:\jdk1.3.1_02\bin\jar c Assign1 > Assign1.jar
This tells the OS exactly where to search to find the jar program. (You can do the same for javadoc, javac, etc.)