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 the latest release of BlueJ and obtain information about downloading a matching version of Java.

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 (package) 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

On newer releases of BlueJ, you can copy the contents of an entire package all at once: Say that you want to copy a package Q in its entirety into Assign1:

  1. Open the window for Assign1.
  2. Select Edit and then New Package. Type the name, Q, into the dialog.
  3. Open the window for Q; select Project and then Import. Use the file dialog to locate the folder (package) named Q on your file system.
BlueJ will then copy all the classes in folder Q into the BlueJ package Q you just constructed.

II. Using javadoc and jar

javadoc

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.

jar

We use the jar program to prepare a CIS300 assignment for submission. Newer versions of BlueJ let you construct a jar file.

Unfortunately, the jar file that BlueJ constructs does not retain the project folder when jar-ring. This makes the result of opening the jar file messy, because the project folder is lost, and the internals are scattered across the disk. For this reason, you must use a command-prompt window (an ``MS-DOS window'') for constructing a jar file.

How to use javadoc from the command window:

To use javadoc on a project folder Assign1, do the following:

  1. Open a command-prompt window. (To do this, click on Start, then click on AllPograms, then Accesories, then ComandPrompt.)
  2. Within the window, repeatedly type the cd command to change to the directory where Assign1 lives. (If you have never used the cd command, ask a friend, or a TA, or the instructor.
  3. When you locate the folder, Assign1, type cd Assign1. When you type dir, you will see the names of all the packages in the folder.
  4. To generate the API web-pages for all classes in package P, type javadoc -classpath . P
If this does not operate correctly (e.g., you see the message, `javadoc' is not recognized...), see the note below.

How to use jar from the command window:

Say that we wish to ``zip'' the project folder, Assign1, into a jar file. To use jar, do the following:

  1. Open a command-prompt window, as described above.
  2. Use cd to find the folder, Assign1.
  3. Type jar c Assign1 > Assign1.jar
If this does not operate correctly (e.g., you see the message, `jar' is not recognized...), 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, please read the information in the page, Setting the ``path'' variable for using the JDK with Windows.