How to build the code for
Thinking in Patterns with Java
by Bruce Eckel


  1. Download and unzip the code from Thinking in Java, 2nd edition into a directory that will be referred to as code. (Some of the libraries from this book are used in the Thinking in Patterns code).

  2. Add the code directory for the Thinking in Java, 2nd edition source code listings (that you unzipped in step 1) to your Java CLASSPATH. Note that in order to successfully compile all of the Thinking in Java files requires the installation of additional Javasoft libraries and a C++ compiler. However this is not necessary in order to compile the Thinking in Patterns code. Thinking in Patterns uses some of the basic Java libraries from Thinking in Java so you must have that code available.

    • You must also include '.' in your CLASSPATH, otherwise Java will not look in the current directory.

  3. Download and unzip the book Thinking in Patterns, which includes the code, from Mindview.

  4. Add the code directory for the Thinking in Patterns source code listings (that you unzipped in step 3) to your Java CLASSPATH.

  5. Download and install the Java 2 SDK (JDK 1.3 or higher) from Sun.

  6. Download and install Python (the latest version should work fine) from www.python.org. Add the Python directory to your PATH.

  7. Create a new environment variable (in your AUTOEXEC.BAT under Windows, in your .cshrc under Linux) called PYTHONPATH, and add the python home directory to this path. Make sure you leave no spaces around the '=' sign when creating this path. For example, here's my PYTHONPATH:
    set PYTHONPATH=.;c:\PROGRA~1\Python;c:\PROGRA~1\Python\PIL;C:\ProgTools\Python;C:\PR OGRA~1\Python\HTMLgen;C:\Progtools\Jython;c:\aaa\Python;

  8. Download and install Jython from sourceforge.net. This is necessary to compile the Interpreter/Multiple Languages chapter. The installer is built into the .class file, so all you need to do is run that file with Java.

    • However, When installing Jython, you must explicitly specify the path to the java executable that's in your JDK. If you just say java Jython-20, then you will end up using the default java, which will be in the JRE if that's installed, and you won't get the right results, in particular for jythonc. For my machine, I used the command:
      C:\ProgTools\java\bin\java.exe Jython-20
      to install Jython, and you'll need to give a similar command, depending on where your java.exe is located.

    • Add Jython.jar (which was produced by the previous step) to your CLASSPATH. Add the Jython install directory to your PATH.

  9. Download and install Gnu make from Simtel for DOS/Windows. You can find general information about make and places to download it for other machines at the Gnu make page. Note that Linux automatically installs Gnu make. Windows NT may require some fooling around in order to get Gnu make to run, but I have seen it work (you may be able to find specific notes by searching the Internet; try Google).

    • Here are some notes from Xandy Johnson at FGM, Inc., who solved the Windows NT problem, albeit with the use of Cygwin: The main thing is to use Cygwin. The really important part of this is that Cygwin get you a real shell, which none of the Windows command processors (i.e. COMMAND.COM on DOS/3.1/95/98/Me and cmd.exe on NT/2000) are. I invoke 'make' from a Cygwin bash prompt, which should work with nothing additional beyond installing Cygwin. If you want to be able to invoke make from a DOS Command Prompt, you need to do a couple of additional things: (1) add the Cygwin 'bin' directory (e.g. C:\cygwin\bin) to your PATH, and (2) set the environment variable MAKE_MODE=unix. Setting MAKE_MODE=unix will cause make to use /bin/sh as the shell, rather than cmd.exe, which is, as I said before, one of the crucial differences in Cygwin.

    • To get Jython to work under Cygwin, here's what I had to do (note that I first installed Jython on Win98, then later installed Cygwin. Perhaps there's a way to install it under Cygwin that would not require this). Copy the batch files jython.bat and jythonc.bat to cygwin's /usr/local/bin, since that's already in the path (and an empty directory, on mine, anyway). Then change their names to jython and jythonc. No '.bat' (Unix is literal about names, and doesn't infer the extension, as is assumed in the makefile). Now the jython shell script must be Unixified (there's probably some other way to do this in Cygwin, but at least I got it to work). Remove all the rem statements, and change the direction of the slashes, and when you're done you should get something like this for jython (it's what I used):

      #! /bin/sh
      D:/jdk1.3/bin/java.exe "-Dpython.home=D:/jdk1.3/Jython" -classpath "D:/jdk1.3/Jython/jython.jar;%CLASSPATH%" org.python.util.jython $1 $2 $3 $4 $5 $6 $7 $8 $9


      You should then be able to type "jython" at a Cygwin prompt, and get the >>> sign for interactive python.
      Your jythonc will end up looking like:

      #! /bin/sh
      jython D:/jdk1.3/Jython/Tools/jythonc/jythonc.py $1 $2 $3 $4 $5 $6 $7 $8 $9


    • Finn Bock writes: I managed to get gnu make to work on my win2k by adding this to c09/makefile just before the "all:" target:

      ifeq ($(OS),Windows_NT)
      COMSPEC=$(SYSTEMROOT)\system32\cmd.exe
      endif


      The default shell set by Gnu make seems to be COMMAND.COM, and as Xandy explained, that shell (on w2k) is too simple minded for the task. But CMD.EXE is sufficiently powerful for the commands in your makefiles. With the patch to c09/makefile, I could run "make" from a cmd.exe prompt.

  10. Move to the code directory for Thinking in Patterns. To a command prompt, type
    make javac
    if you are using the Sun JDK compiler or
    make jikes
    if you are using the IBM Jikes compiler (much faster, better error messages).

  11. All the code should compile without make aborting. In addition, all the Unit Tests will be run to verify that the programs behave properly.

    Note that some of the needed utilities in the Thinking in Java directories may or may not automatically compile during this process — if they do not, make will abort, and you will need to go to the appropriate Thinking in Java directories and type make.

Home