Q:

Is there any way to include Antlr in the Java compilation process?

I am using Antlr4 to create a Java (Java 7) source transformation tool. I take as an input a Main.java file and transform it to an output newMain.java source file, which corresponds to the same program, but with minor changes. To run my transformation tool I am using the exported generator.jar file as follows:
Step1 (I use the generator.jar to create the newMain.java file by using the following command):
java -jar generator.jar folderName/Main.java

Step2: (I compile the newMain.java file)
javac folderName/newMain.java

Step3: (I run the newMain.class file)
java newMain

I was wondering if there is any other way of doing this operation, which would be transparent to the user (through command line or by using an IDE)? I mean that the user should just compile his Main.java class without seeing the generated newMain.java source file neither the newMain.class. Actually, the new generated .class file should replace the initial Main.class file.

A:

I don't know what build tool you're using, but you mentioned command line, so maybe something like this in Bourne shell:
#!/bin/sh

FOLDER=folderName
CLASS=Main

java -jar generator.jar $FOLDER/$CLASS.java

javac $FOLDER/new$CLASS.java
/bin/mv $FOLDER/new$CLASS.class $FOLDER/$CLASS.class
/bin/rm $FOLDER/new$CLASS.java

java $FOLDER/$CLASS

This is just real simple and doesn't do any error checking (e.g. translation or compilation errors).

