Laboratory: Getting the Book Code
CSC 207 Algorithms and Object Oriented Design Spring 2011

Summary: In this lab, we will download, organize, and compile the standard code accompanying our textbook.


  1. Create a directory for the book code to live in:
      mkdir somewhere/book
  2. Go to your new directory:
      cd somewhere/book


Exercise 1

  1. Download the book code:
  2. Unpack the code (be sure you are in your special directory!)

Exercise 2

  1. Change to the newly created code directory:
      cd code
  2. Create a new subdirectory for the source files called src:
      mkdir src
  3. Move the source files into src:
      mv *.java src
      mv weiss src

Exercise 3

  1. Copy the Ant build file to your code directory (not the src directory)
      cp ~weinman/public_html/courses/CSC207/2011S/labs/code/bookcode/build.xml .
  2. Run a test of building the code from the command line by running Ant.
    This should create a directory class where it stores all the compiled class files.

Exercise 4

Now, we need to configure JDE so that it is aware of your files, and ant, so if you edit any of them you can build directly from within Emacs.
  1. Copy the JDE project file to your directory:
      cp ~weinman/public_html/courses/CSC207/2011S/labs/code/bookcode/prj.el .
  2. Open any source file in Emacs. For instance,
      emacs src/weiss/util/ &
  3. Now, we are going to build the book code as a JDE "project." There are two ways to do this.
    • Select JDE ~ Build
    • Type C-c C-v C-b
    Do one of them now. Contact someone for help if you have any problems (i.e., ant fails to indicate a successful build.)

Exercise 5

Finally, the last thing to do is tell JDE where to find these classes when you compile things. That is to say, we need to add it to your classpath.
  1. Open your ~/.emacs file for editing (probably in Emacs).
  2. Find the line that looks like this:
    (setq jde-global-classpath (quote (".")))
  3. Note that you put the book code in somewhere/book/code, and you decided where somewhere is. The source files live in somewhere/book/code/src, and you've just configured the compiled class files to live in somewhere/book/code/class. Change above line in your ~/.emacs to read instead:
    (setq jde-global-classpath (quote ("." "/home/username/somewhere/book/code/class")))
    being sure that you replace somewhere with the appropriate directory you put things in. (Include the leading slash to make the directory absolute, rather than relative.)
  4. If you want to compile and run your testing code from within JDE, you'll also need to let JDE know where your tester.jar file lives if you haven't already. To do this, you can amend the line you changed above to something like:
    (setq jde-global-classpath 
          (quote ("." "/home/username/somewhere/book/code/class" 
    being sure that you replace somewhere-else with the appropriate directory you put things in for the testing lab.

    Once again, be sure to include the leading slash.

  5. Save your file and exit emacs.

Exercise 6

  1. Go to the parent directory:
     cd ..
    You should now be in somewhere/book
  2. Copy a simple test file and open it in emacs.
    cp ~weinman/public_html/courses/CSC207/2011S/labs/code/bookcode/
    Open the file with emacs and inspect it briefly to see what it does.
  3. Compile the code within emacs. Note that you will not be able to compile from the command line without specifying the book code's classpath.

    If you are unable to compile the code, there is a problem with your configuration. Make sure the path you added to emacs actually matches the location of the compiled class files.

Created: Jerod Weinman, 12 January 2009
Modified: Jerod Weinman, 17 January 2011
Modified: Jerod Weinman, 4 March 2011