jam: java automated make a simple generic makefile for java projects Another Aromatic Productions http://www.aromatic.com/ Copyright (C) 1998 Raffaele Sena (raff@aromatic.com) All rights reserved ----------------------------------------------------------------------- ABOUT jam --------- The majority of java source packages seems to come with the note: "In order to build the project, just compile all the java files in this directory or directory tree". Very few come with a script and none with a makefile. So, what your alternatives are ? - manually run the java compiler every time you have to recompile a file - write your own script, that probably will recompile everything every time you run it - write your own makefile. List all the java source file in the current project, and write a simple rule to compile them. And, in the latter case, all the makefiles you write for the different project look the same. They are very simple, but nevertheless they take time to be written. For this, and strong on the idea that if I have to spend my precious time I prefer to spend it in creative ways than in dummy, repetitive operations, I wrote jam, a very simple tool for building java projects. jam is basically a generic makefile, based on gnumake, that does exactly what is needed. Look in the current directories for java source files, setup a list of targets and make them if needed. CONFIGURING jam --------------- There is also support for an external definition file, that you can add in the top directory of your project, to add or change the behavior of the generic makefile without modifying the original. So, if you need to use specific options, or a different compiler in one of your project, just create a file 'jam.def' with the following line: JC = for example, to use guavac instead of javac (the default compiler) and you need to add specific classes to the environment, jam.def will contain JC = guavac -classpath $CLASSPATH:myclasses.jar Also, if you set JMAIN to the name of the class containing your main program, jam will generate two target you can use: run: to run the specified java program debug: to debug the specified java program The command used to run and debug a program are defined by the make variables JVM (for run) and JD (for debug). The default for JC, JVM and JD are the standard JDK commands: JC = javac JVM = java JD = jdb As a standard gnumake feature, you can change those variables (for example to add a specific classpath) by adding parameters in jam.def. For example, to add myclasses.jar to the classpath, add the following lines to jam.def: JC += -classpath $(CLASSPATH):myclasses.jar JVM += -classpath $(CLASSPATH):myclasses.jar JD += -classpath $(CLASSPATH):myclasses.jar That's all. For generic use you shouldn't need to change anything. INSTALLING jam -------------- The jam package is composed of two files: jam: a simple script to run the makefile makefile.jam: the generic java makefile Copy the two files in a directory present in your path (i.e. /usr/local/bin). If you got the files from my original tar archive, jam should already be marked as executable, otherwise change the attribute appropriately (i.e. chmod +x jam). RUNNING jam ----------- jam should now be ready to be used. Go in a directory containing java source files you want to compile and type jam. That would do it. Parameters passed to jam on the command line are passed to the make command as they are. So you can specify debugging options or the targets you want to make. For more information see the make documentation. A 'clean' target is also defined to remove all the class files: jam clean As specified before, if you set JMAIN in your jam.def file, you can run your program by typing: jam run and debug it with the command: jam debug NOTES ----- - As explained before, jam makes use of gnumake extensions. And internally uses the 'find' command, that should also be present in your path. - The jam script expects $0 (the program name) to be a fully qualified pathname, so that it can look for makefile.jam in the same directory. If your shell works differently, you can set bindir to the absolute path of the directory you installed jam. - When running jam for the first time in a project directory, if you didn't create jam.def, you will get a warning error. After that, jam will create an empty jam.def and the error will disappear in successive run. - Final note. It should be clear by now that jam is a U*ix tool. It make use of standard utilities available on most of the U*ices available on the market. And has been developed and tested on Linux. It should also work on other environments where gnu tools have been ported (i.e. Windows 95 and Windows NT) but I cannot really assure you that. If you find this tool useful, or you have ideas for improving it, send me a note at raff@aromatic.com. jam is available at: http://www.aromatic.com/tools/