Running MyBatis Generator From a Command Prompt
MyBatis Generator (MBG) may be run directly from a command prompt. The JAR manifest includes the
name of the default class (org.mybatis.generator.api.ShellRunner
)
or you may specify it yourself. The ShellRunner
class accepts several arguments as detailed below:
Argument | Value |
---|---|
-configfile file_name (required) |
Specifies the name of the configuration file. |
-overwrite (optional) | If specified, then existing Java files will be overwritten if an existing Java file if found with the same name as a generated file. If not specified, and a Java file already exists with the same name as a generated file, then MBG will write the newly generated Java file to the proper directory with a unique name (e.g. MyClass.java.1, MyClass.java.2, etc.). Important: The generator will always merge and overwrite XML files. |
-verbose (optional) | If specified, then progress messages will be written to the console. |
-forceJavaLogging (optional) | If specified, then MBG will use Java logging rather than Log4J even if Log4J is in the runtime classpath. |
-contextids context1,context2,... (optional) |
If specified, then this is a comma delimited list of contexts to use in
the current run. Any id specified in the list must exactly
match the value of the id attribute of an
<context> configuration element. Only ids specified
in this list will be active for this run. If this argument
is not specified, then all contexts will be active. |
-tables table1, table2,... (optional) |
If specified, then this is a comma delimited list of tables to use in
the current run. Any table specified in the list must exactly
match the fully qualified table name specified in a
<table> configuration element. Only tables specified
in this list will be active for this run. If this argument
is not specified, then all tables will be active.
Specify table names as: table schema.table catalog..table etc. |
You must create an XML configuration file to run MBG from the command line. If the file is named "generatorConfig.xml", then any of the following command lines will run MBG:
java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml java -cp mybatis-generator-core-x.x.x.jar org.mybatis.generator.api.ShellRunner -configfile generatorConfig.xml -overwrite