CodeWarrior At Stanford
CodeWarrior is a modern IDE (integrated development enviroment)
that packages the compiler, editor, and debugger for
Java, C, and C++.
Stanford has a site license for CodeWarrior Mac and PC.
The IDE and documentation may be downloaded
here with
a Stanford login. The download package includes the Java compiler
materials for each platform, and there is also a link
including the many PDF docs for the compiler.
The Mac clusters have the same Codewarrior image installed that you
can download above.
Update there are some further updates (8.3) to the above
download available from metrowerks
that are worth installing for java development (although they
are not crucial).
To run Java programs, you will also need to install a recemt Java JDK
(Java Development Kit) from Sun.
It's probably best to install the most recent JDK first, then Codewarrior.
The "JRE" is different -- that's just for running Java, not compiling Java.
PC and Linux people get Java from Sun.
Mac OSX come with java installed by default.
It's possible to run Java 1.1 on Mac OS 9, but that version of java is
pretty old, so you we recommend OS X instead.
The most recent Apple java updates are available from
apple itself.
CodeWarrior Tips
- CodeWarrior keeps track of everything in a project file
with a name like 'project.mcp' which is generally kept in a directory along
with all your sources. The project file knows the names
of your source files, the build preferences,,
and a pointer to the library rt.jar or classes.zip file containing the java library
files, such as String. The compiler uses uses the rt.jar file
at compile to to error check that your code uses the classes, messages, etc. correctly.
You can have a project with no jar file at at all, and in the system
will silently use some default rt.jar file, so that can work too.
- To get started, make a project. You can make an empty project,
or use the "wizard" to make a new java application project.
Uncheck the "create an initial form" option.
Put your .java files in the same directory as your .java files and
add the .java files to the project. Use drag-n-drop to drag
files from the file system to the project window directly.
-
Use command-0 to bring up the project window quickly
- There is a button on the project window to bring up
the preferences for that project.
- Use the 'java target' option
to specify the main class name. (Do not set the command line options here. These options are for the java interpreter, such as -Xint).
- Use the 'runtime settings' option to set runtime
command line options if you'd like to pass command line arguments to
your java program.
- Use the 'java output' option to control if the files are compiled
to .class files or a .jar file, and if the main-class manifest
entry is generated in the .jar file.
-
Use the 'Compile' command (command-k) to just compile the file you are currently looking at --
fix the syntax error -- repeat. The CodeWarrior compiler is much faster
than javac. You can iterate through simple errors very quickly. This is
one area where the GUI/IDE really shines. You can edit your code
right in the error-report window.
-
Use the 'Make' command (command-m) to compile everything and generate .class
or .jar output.
-
Use the 'Find Definition' command to skip to the definition of a method
-
Use command-e to enter the current selection as the find string, command-g
to cycle through the occurences of that string -- a handy way to move through your own source code.
-
Use command-shift-b to got "back" if you've been following symbols forward
-
Use ctrl-period to lookup method name completions as you type -- quite handy!
Type the first few letters of the what you want to narrow the list.
This can work automatically each time you type a period -- turn that on or off
in the Codewarrior (not project) preferences, in the Code Completion section.
- Look in the Metrowerks:Java Support directory for a compressed archive of the
java sources. If you expand that archive, then Codewarrior will
be able to pull up Java source files very quickly, which can be a
handy way to read the docs (command-d with an empty selection).
- The find-file feature can look through entire directory trees, and
there is a fancy graphical diff feature.
Debugger Tips
-
The debugger is functional but slow -- many people prefer System.out.println()
for simple problems, saving the debugger for scary debugging..
-
The debugger is slow at stepping -- set breakpoints and "run" to keep it
bareably fast
-
Click the little button in the stack variable display to set it to "auto"
instead of "all".
-
Use the "breakpoints" window to turn breakpoints on and off temporarily,
without removing them from the source -- handy!
Java on Mac OSX
Mac OSX includes a Java right out of the box.
As of OSX 10.2, Java 1.3 is included.
Older Mac OS versions can run Java 1.1, which can be made to
work for most things, but using OSX is the easiest way to go.
There are some OS9 instructions below, but we recommend OSX.
The Stanford Codewarrior
image includes a simple Java 1.3 app project template to get started.
All a project needs is the "rt.jar" file from the
folder Codewarrior-Java Support- Libraries-JDK1.3.
Codewarrior includes its own templates, but they include
all sorts of extra junk that gets in the way, and I do not
recommend them.
After compiling, the Run command runs the program.
It will fork off a terminal window, and run the program from there.
Or you can just use CodeWarrior to build, and then switch
to the command line to run, just using the regular
command line tools like 'java MyClass'.
Or you can use CodeWarrior to build
its output into a .jar file including a main-class manifest,
and then just double click the .jar to run. The command line
output goes to the console.
Use the get-info panel of the .jar file to change it so it is
opened by 'Jar Launcher'. The standard unix command line tools are
there too, so you can switch to 'javac *.java' if you like.
Trick: type 'cd' in a local terminal, then drag a folder
icon to the terminal. It will paste in the path to that folder.
Java on MacOS
MacOS 8/9 supports only Java 1.1, however Swing and Collections can be
retrofited to it so it works fine for most purposes.
In some cases, an API will be Java 1.2 only, and so will not work on OS9,
but you can work around those cases. (The files
mentioned here are included with the Codewarrior download above.)
Put the swingall.jar and collections.jar files in Codewarrior:Java Support:Libraries
folder -- this makes the classes available at compile time. Also place copies
of those jar files and MWDebugger.jar in the MRJClasss
folder in the extensions folder of the system folder. This makes the classes
available at run time.
Unix <-> Mac OS9
To move a Unix project to the Mac OS9: bring over the .java files, make the
stationery project, add the .java files. Include the "import com.sun.java.util.collections.*;"
line in source files using collections.
To move Mac to Unix: move the .java files back to Unix. Comment out
the "import com.sun.java.util.collections.*" line. There probably needs
to be an import java.util.*; line, and it can be left in for the Mac builds.
Use the fixeol utility in the cs108/bin directory
to fix the line endings of your text files for unix
like this: '/usr/class/cs108/bin/fixeol *.java'.
or just set CodeWarrior to use Unix line endings as its default.