Run MyBatis Generator 1.3.x from the command line and Java program to generate mybatis3.x code

Source: Internet
Author: User

Recently, because of the project needs, research the use of MyBatis 3.x, of course, by the way also studied the use of generator to reverse engineering to generate pojo,mapper and other documents. Before using this tool, download the relevant jar package, I am using the latest Mybatis-generator-core-1.3.2.jar.
Generatorconfig.xml is listed below:

<?xml version= "1.0"  encoding= "UTF-8"  ?><! doctype generatorconfiguration public  "-//mybatis.org//dtd mybatis generator  configuration 1.0//en " " HTTP://MYBATIS.ORG/DTD/MYBATIS-GENERATOR-CONFIG_1_0.DTD " >< Generatorconfiguration >  <context id= "Context1"  >     <jdbcconnection driverclass= "Com.mysql.jdbc.Driver"           connectionurl= "Jdbc:mysql://localhost:3306/test?useunicode=true&amp;characterencoding=utf8"          userid= "Root"           Password= ""  />    <javamodelgenerator targetpackage= "Com.lanx.test.domain"  targetproject= "/home/user/workspace/mybatis-web/src/main/java"  />    < Sqlmapgenerator targetpackage= "Com.lanx.test.mapper"  targetproject= "/home/user/workspace/mybatis-web/src/main/resources/"  />    < Javaclientgenerator targetpackage= "Com.lanx.test.mapper"  type= "Xmlmapper"  targetproject= "/home/ User/workspace/mybatis-web/src/main/java " />     <table  Domainobjectname= ' person '  tablename= ' person '  enablecountbyexample= ' false '                  enabledeletebyexample= "false"   Enableselectbyexample= "false"  enableupdatebyexample= "false"  >         <property name= "Modelonly"  value= "false"/>    </table>      </context></generatorConfiguration>

I placed the XML file under the project root, followed by a similar official document:
Http://generator.sturgeon.mopaas.com/running/runningFromCmdLine.html
Run MyBatis Generator from the command line
As stated in the documentation, execute:

java -jar /home/user/backup/mybatis-generator-core-1.3.2.jar -configfile  Generatorconfig.xml The following error occurred:exception in thread  "main"  java.lang.RuntimeException:  exception getting jdbc driver        at  Org.mybatis.generator.internal.db.ConnectionFactory.getDriver (connectionfactory.java:85)          at org.mybatis.generator.internal.db.connectionfactory.getconnection ( CONNECTIONFACTORY.JAVA:54)         at  Org.mybatis.generator.config.Context.getConnection (context.java:526)          at org.mybatis.generator.config.context.introspecttables (context.java:436)          at org.mybatis.generator.api.mybatisgenerator.generate (MyBatisGenerator.java:222)         at org.mybatis.generator.apI.shellrunner.main (shellrunner.java:117) caused by: java.lang.classnotfoundexception:  Com.mysql.jdbc.driver        at java.net.urlclassloader$1.run ( urlclassloader.java:372)         at java.net.urlclassloader$1.run ( urlclassloader.java:361)         at  Java.security.AccessController.doPrivileged (Native method)          at java.net.urlclassloader.findclass (urlclassloader.java:360)          at java.lang.classloader.loadclass (classloader.java:424)          at sun.misc.launcher$appclassloader.loadclass (launcher.java:308)          at java.lang.classloader.loadclass (classloader.java:357)      &NBSP;&NBSP;&NBSP;&NBSP;AT&NBSP;JAVA.LANG.CLASS.FORNAME0 (Native&nbsP Method)         at java.lang.class.forname (Class.java:344)          at  Org.mybatis.generator.internal.ObjectFactory.internalClassForName (objectfactory.java:150)          at org.mybatis.generator.internal.objectfactory.externalclassforname ( objectfactory.java:121)         at  Org.mybatis.generator.internal.db.ConnectionFactory.getDriver (connectionfactory.java:82)          ... 5 more

In fact, it has been estimated before running, obviously did not introduce the MySQL driver jar package, the modified statement is as follows:

Java-cp/home/user/backup/mybatis-generator-core-1.3.2.jar:/home/user/backup/mysql-connector-java-5.1.36.jar Org.mybatis.generator.api.shellrunner-configfile Generatorconfig.xml

After running, successfully generated files such as Pojo, pay attention to Generatorconfig.xml file Javamodelgenerator and so on several nodes Targetproject attribute configuration, here I have written absolute path. In fact, if there is an error in this configuration, a warning prompt appears when you write a nonexistent folder.

While using Java programs to run MyBatis Generator 1.3.x, copy the code given on this website directly.
The reference URL is as follows: http://generator.sturgeon.mopaas.com/running/runningWithJava.html

Finally, my development environment: Ubuntu Kylin + ECLIPSE-LUNA-SR2 + jdk8


Run MyBatis Generator 1.3.x from the command line and Java program to generate mybatis3.x code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.