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
    • log4j.properties
  • 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

 

CONFIGURATION

Here’s a sample of generatorConfig.xml:

 

JAVA BATCH

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

 ANT TASK

Notice that line:

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

Leave a Reply

Your email address will not be published. Required fields are marked *