MyBatis Generator – How to use MBG

MyBatis Generator – Run MBG

MyBatis Generator can run in several ways, in this guide it will be shown how to run MBG from

  • Java batch
  • Ant

First of all, create your environment with a so built directory tree:

  • src
    • mapper
    • model
    • xml
    • batch
  • lib
    • mybatis-generator-core-x.x.x.jar
    • mybatis-x.x.x.jar
    • log4j-x.x.x.jar
    • (jdbc drivers.jar)
  • build.xml
  • generatorConfig.xml



Here’s a sample of generatorConfig.xml:



In batch package, create class called Generator and put this code:


Notice that line:

allow to find into src folder; otherwise, log4j should be located into project root folder.

Be the first to comment

Leave a Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see