|
Comp201: Principles of Object-Oriented Programming I
Spring 2008 -- Projects
in DrJava
|
DrJava's Project facility allows the developer to organize
their work into a cohesive unit. It allows the developer to
- Manage multiple files and multiple packages easily
and effectively
- Distinguish between files that are part of a
particular piece of work, separate from other files used for reference.
- Separate compiled from non-compiled code.
Creating a Project in DrJava
- First create a directory that will hold all the code
and supplemental materials for your project. Use a folder name that is
relevant to the project.
- Below that directory, make two subdirectories:
- src --
holds all the Java source files. Put any existing source
code you have in here. If the code is in a package, then put the
entire package directory here.
- classes --
holds all the compiled class files.
- Start DrJava and select Project/New...
- Browse to the desired directory for your project,
usually your homework directory, e.g. "U:\Comp201\HW03".
- A dialog will pop up with project property options
for you to fill out:

- Project Root: This is where the
source files for the project (.java, .dj0, .dj1, .dj2) are to be kept.
Click the "..." button and using the dialog that comes up, create a
sub-folder called (by convention) "src".
- Build Directory: This is where
the compiled .class files will be created. It is kept separate
from the source files because these are all auto-generated by DrJava.
Click on the "..." button and use the dialog to create a sub-folder called
(by convention) "classes".
- Working Directory: This is the
directory where the interactions pane and any executing Java programs will
expect to find any additional files to load under programmatic control.
Set this either to the same directory as your project, or the
classes directory. The latter will give
greater compatibility if you ever decide to run your programs from outside
of DrJava from a command line prompt.
- Main Document: If you know what class holds the
main() function, set the Main Document
field to that class in the src
directory.
- Extra Classpath: Sometimes
auxiliary code will be supplied in the form of
Java JAR files. This is where you would tell DrJava to find
these files.
- Go to File/Open Folder... and open the
src directory (should open by default). This will
bring in any existing code that you have.
Adding a File to the Project
- Add a file to the project using File/New... or the
speed button as usual. The file will be added to the project
when it is saved with a name.
- The same applies for new unit tests.
Compiling the Project
- Under the Project menu, select Compile
Project to compile everything in the project or Compile Open Project
Files to compile just the files that are open.
- The Compile All speed button compiles all
files whether or not they are in the project.
Testing the Project
- Under Projects, select Test Project.
Clearing the compiled files
This feature is useful when zipping up project
directories when you don't wish to include the compiled class files.
- Under Projects, click on Clean Built
Directory. This will erase all files in the
classes folder.
Last Revised
Thursday, 03-Jun-2010 09:50:27 CDT
©2008 Stephen Wong and Dung Nguyen