Cool JavaBuild

As part of my recent foray back into Java programming, I downloaded some Java code from the Advanced Java 1.1 Programming site (It's the second Java book I'm reading, and I'll admit that I liked the Core Java (Volume I) book more.  I'd like to read some newer Java books, but this is what I could easily lay my hands on.  But that's not germane to this page.

It turns out that all the pre-built .class files were built a long long time ago, and my new JDK 1.2.2 installation seems to pretty much barf on them when I try to use any of their stuff.  Soooo, I needed to recompile all their stuff.  Now, given how many files are there (it's gotta be like 80 or more), I really didn't want to do it by hand.  And I figured that it would be annoying to do some fancy cut-and-paste thing to create a batch file for it.  Enter the magical Java builder.  It's crummy code I threw together (I'm sure I could make use of better naming conventions and more available packages for my path parsing, but mine seem more readable to me than File::Parse) and refined during the build cycles.  I think I got it pretty good before I managed to build every file that would build.  There are still over 20 files that won't build (files using deprecated stuff mostly, or dependencies on said files), but hey, it built the files I needed!

It is intended to build from a source directory into a destination directory (which should not be the same, though it probably won't cause real problems).  The nice part is that it makes multiple passes through the source files.  It expects every .java file to build into a .class file of the same name.  If this is not true, it will not notice the file as having been built and will ignore it for its statistics.  This keeps these from confusing the script into cycling endlessly.  Even so, given that it doesn't do any form of dependency checking, the execution time can be expected to grow in O(n2) time.  Just let it run a few hours if necessary.

The script only takes a few arguments.  If you have Perl installed and associated with .pl files, you can run this off the command line or write a batch file to do it.  Here's the usage and an example:

cool_javabuild.pl SrcDir DestDir Classpath
cool_javabuild.pl \jdk1.2.2\ajp\src\ajp \jdk1.2.2\ajp\code\ajp
     \jdk1.2.2\ajp\code

The Classpath is usually the parent of the dest dir.  If you need multiple paths you'll have to hack the source, Luke.  Speaking of which, here's the script.

Note:  I wrote this script because I figured that the only way to automatically build dependencies would be with a commercially available package.  This isn't the case--my co-workers informed me the very next day that javac can take a dependency switch, which causes it to build all dependencies.  Still, this is a good use of File::Find.

This script uses the "File" package extensively, which you can get with ppm.

I have more Perl info here.


Back to my home page