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.

Leave a Reply

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