Starting the code generator from the command line
You can run the code generator from a commandline (console) and have control over a number of important options. But even if you only plan to use the code generator in a windowed environment, you might want to read up on these options because you could create customized shortcuts that pass the arguments that set up your environment perfectly.
The general format of a code generator invocation is:
jcpp [option-list] [modelfile]
Let's start with a complete list of code generator command line options
||Adds the directories contained in the file to the library search path in the generated project files.
||This optional argument allows you to generate projects with correctly set up library search paths. The directories are expected to be represented by their names, one per line.
||Adds the files listed in the specified file to the generatede project files.
||This optional argument allows you to generate projects with additional source files. The files are expected to be represented by their names, one per line.
||Run the code generator in commanline mode (no GUI)
||This option should usually be used together with the -generate.net option.
||Allows you to specify a classpath that is automatically added to newly created or processed Java models.
||Specifying a classpath allows you to provide information about the location of jarfiles or classfiles on the commandline.
||Same as -cp
||Allows you to specify a system property.
||Start the code generator (with a supplied modelfile) and immediately generate the C# code for the specified model.
||This option is usually used together with the -cli option to achieve commandline generation of an already created model.
||Start the code generator in GUI mode.
||This is the default option if -cli is not specified.
||Display a list of options and some useful examples.
||Allows you to specify a JRE that is used by the code generator itself.
||This option is only useful on Windows. A normal user never has to use this options.
||Allows you to specify the name of the file to which the code generator logs comments.
||Allows you to override the target directory of a commandline generation.
||Normally, you specify the output directory in your modelfile. This option allows you to override this setting.
||Display code generator version information and exit.
||Treat warnings as errors.
||Display code generator version information and continue.
||Allows you to specify a list of set specification files that were generated by earlier invocations of the code generator.
||Each time the code generator generates C# files, it also generates an XML file that contains descriptive information about the files it generated. You can pass this so-called "set specification file" to subsequent code generator sessions to tell the generator that certain types have already been generated and should not be generated again, even if they are marked as generating.
Read more about this feature here.
||Allows you to specify the heap available to the code generator.
||You might have to set this option to -Xmx768m or higher if you generate large sets.
||Same as -help
In addition to the options specified above, you can also pass any standard Java option.
Now let's look at some examples.
This example demonstrates a simple code generator invocation with a classpath. Invoking the code generator with a classpath allows you to import types by name if they are located in any of the classpath roots you specified.
jcpp -cp ".;c:\temp\myclasses.jar"
Please remember to doublequote the path to avoid problems with spaces in filenames. Without specifying the classpath you can still specify a classpath for your model, but you will have to enter it in the "Create Java Model" dialog.
This example demonstrates a simple code generator invocation with an existing modelfile. Invoking the code generator like this quickly puts you back to where you left off without you having to manually opening the modelfile when the code generator GUI is up.
Without specifying -cli and -generatecpp, the code generator is going to start in GUI mode and you can make further edits to the modelfile that you opened. By putting th is little snippet into a batch file called "edit_mymodel.bat", you can simply doubleclick the batch file.
This example demonstrates a simple code generator invocation with an existing modelfile. Invoking the code generator like this generates C# proxy classes and exits.
jcpp -cli -generate.net c:\temp\mymodel.cmm
This would be the basic invocation used in an automated build or when you have created a batchfile to quickly regenerate your proxy classes after you made changes to your Java classes.
This example demonstrates a simple code generator invocation with an existing large modelfile. Invoking the code generator like this generates C# proxy classes and exits.
jcpp -Xmx768m -cli -generate.net c:\temp\mymodel.cmm
Here we give the code generator 768MB of heapspace. Do this (or even more) if the code generator runs out of memory during processing or code generation. An out-of-memory condition might result in weird generation error rather than a formal error condition.