Javapp is an attempt to do two things : produce a preprocessor suitable for java ( and using UTF-8 ) and use a style and methodology that's familiar to C and C++ users while adding functionality and removing some of the C preprocessor's more irritating behaviors.
Now using preprocessors is something that's made annoyingly difficult by the java compiler. While it's quite happy to let you compile a file and automatically compile all the source files it depends on, it has absolutely no provision for letting you preprocess them automatically. I solved that issue by developing a compiler enhancement called javacx which you can also find on Sourceforge.net.
So with that solved I could turn my attention to what preprocessor to use.
Javacx can use the C standard preprocessor ( with suitable options ) or you can specify another command or even a chain of commands to use as to preprocess source files. The C preprocessor, which I've used for decades, has some issues which I wanted to address and the keys ones are :
I think those are enhancements which most macro users would regard as useful. In any case I find them useful, so they're in. :-)
Not a great deal of difficulty here, but you need to use the C preprocessor either explicitly or via javacx.
If you're wondering why anyone would use a C preprocessor when compiling java, then you're probably not a good candidate for using javapp, although I'd encourage you to consider using macros in your code, as it adds a new tool which, personally, I'd miss.
Using javacx
:::sh
javacx -javacx:cpp javapp.java
Using javac and cpp
Slightly more messy as you need to create a temporary dir to hold the preprocessing result. This is because of another java compiler limitation ( or feature :-) ), which is the requirement to have the filename match the class name it contains.
:::sh
mkdir buildtmp
cpp -P -C javapp.java > buildtmp/javapp.java
cd buildtmp
javac javapp.java
mv javapp.class ../.
cd ..
rm -rf buildtmp
You can probably see from this why I wanted javacx in the first place. Note that javacx does
Of course the ideal way is to use javacx, but if you don't do that you need to use an approach like the temporary directory.
The command line for javapp is simply :
:::sh
java javapp { [-D <macroname>] | [sourcefile] }
The -D option defines a macro name. You can test againsts that macro name but if you use it outside of a conditional test it will be replaced by an empty string.
Anything other than -D <macroname> is assumed to be a file to be processed.</macroname>
You can have as many -D defines or file names as you like. They will be process strictly in teh order they appear on the command line. Note that definitions are cummulative. If you define something in one file and then process another file in the same command, those definitions from the first file are still active when you start the second file.
Like the C preprocessor, javapp sends it's output to stdout, so you need to redirect that to a file or process.
There are currently no command line options.
The wiki section [Macros] shows the macro capabilities in detail.
Links