06 Running the code generator - oldgreydog/CodeGenerator GitHub Wiki
Most people will only need the executable release provided in the releases page of the project. The code_generator.zip file contains everything needed to run the generator as well as the examples. The javadocs are in a separate zip file. In the examples/codegenerator
folder there is a (Linux) batch file named generate_all
that will call the generator for all of the example sub-directories below it. I don't have a Windows machine to test with, so you'll have to tweak that file for now. I'll try to add a Windows version later.
Using the release files
Extract the code_generator.zip file in the directory of your choice. I have included the Linux (generate) and Windows (generate.cmd) batch files that you can use in your batch files to run the generator. Here's an example Linux batch file that calls this generate (assuming that you put the code generator at /home/yourname/dev):
(Note: All of these examples are for Linux, but the Windows versions are almost identical. You should be able to easily port them to Windows syntax if you need to.)
pushd /home/yourname/dev/code_generator
source generate /home/yourname/dev/templates/dbTemplates/database.root.template /home/yourname/dev/projects/myProject/src/dbAccess/DBAccess.xml
popd
The pushd gets the current-directory pointed to the code generator directory so that the generate batch file has the correct context to run in. Then generate is called with the file path to the target root template and the file path to the config values XML file.
If you use the "global.outputPath" value the way I do in the examples, then you can put your files wherever you want them. I have always put the template sets in a single folder and the config values XML files with a generate batch file in the folder in the code tree where the generated code will live (in my case, I generate to a temp folder and then merge to the final location in the code tree, but the idea is the same in the end). Here's an example folder tree to illustrate this:
/home/yourname/dev/
code_generator/
generate
...
templates/
dbTemplates/
database.root.template
...
apiTemplates/
api.root.template
...
projects/
generate_all
...
myProject/
src/
dbAccess/
DBAccess.xml
generate
...
apis/
authenticationAPI/
AuthenticationAPI.xml
generate
...
Note that I put a "generate_all" batch file at /home/yourname/dev/projects
. That's something that you can do, too, if you want to have an easy way to re-generate everything in the tree at one time. I have one in my tree and it contains calls to each of the individual generates in the tree like this (again, a Linux example):
pushd /home/yourname/dev/projects/myProject/src/dbAccess
source generate
popd
echo
pushd /home/yourname/dev/projects/myProject/src/apis/authenticationAPI
source generate
popd
echo
The echos put a blank line in the output so that it's a little easier to visually parse the output at a glance.