Presents your JAVA E-NEWSLETTER for August 22, 2002 <-------------------------------------------> JAVA DEVELOPMENT FROM THE COMMAND LINE Developers have long been split between the Mac/Windows world of point-and-click and the UNIX world of command-line programming. With the advent of OS X on the Mac and the existence of the Cygwin application on Windows, Mac and Windows users can use UNIX command-line power at the same time they use Mac/Windows point-and-click simplicity. There are different command-line environments. Currently, the most popular ones are bash, tcsh, and zsh. We'll use the bash command line for our examples. The first script is all about making life easier for simple environments. This compilation is done from the command line: jikes com/generationjava/example/FirstClass.java Rather than typing java com.generationjava.examples.FirstClass to test this code, why not use the javad function and the !:1 syntax? javad !:1 The !:1 tells the system to repeat the first argument from the line above, starting at zero, and that javad is a simple command-line function: # Run a file from its source filename and not just its # fully qualified class name. function javad( ) { source=$1 shift 1 java `echo ${source} | sed 's/\.java$//' | sed 's/\//./g'` $* } Those of us who are particularly lazy might want to compile every Java source file in a directory. We can accomplish this with javacdir com/ using the following javacdir function. # Compile everything in a directory. # change javac to jikes if need be function javacdir( ) { jikes `find $1 -path '*.java'` 2>&1 | more } When we run javacdir, we get a bunch of errors, which might make it difficult to tell which classes didn't compile. So we want to list out all the source files that don't have a class file yet. Let's use the missingc function with missingc com/: function missingc( ) { for i in `findj $1` do if [ -e `echo $i | sed 's/java$/class/'` ]; then echo XXXX else echo $I fi done | grep -v 'XXXX' } This will list all java source files that still lack a class file. Installing these functions involves adding them to a text file and running the source command on the text file. ----------------------------------------