Recently because of the project needs, investigated the use of MyBatis 3.x, of course, also studied the use of generator to generate pojo,mapper and other documents by reverse engineering. Before using this tool, download the relevant jar package, and I'm using the latest Mybatis-generator-core-1.3.2.jar.
Here's a list of generatorconfig.xml:
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en 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?us Eunicode=true&characterencoding=utf8 "userid=" root "password=" "/> <javamodelgenerator targe Tpackage= "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 "EnableC
Ountbyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" enableupdatebyexample= "false" > <pro Perty name= "Modelonly" value= "false"/> </table> </context> </generatorConfiguration>
I placed this XML file in the root of the project, 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 document, 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.Conne Ctionfactory.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) at JAVA.LANG.CLASS.FORNAME0 (Native method) at Java.lang.Class.forName (class.java:344 ) at Org.mybatis.generator.internal.ObjectFactory.internalClassForName (objectfactory.java:150) at Org.myba Tis.generator.internal.ObjectFactory.externalClassForName (objectfactory.java:121) at Org.mybatis.generator.internal.db.ConnectionFactory.getDriver (connectionfactory.java:82) ... 5 more
In fact, before the run has been estimated, obviously did not introduce a MySQL driver jar package, modified statements are 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 the operation, the smooth generation of Pojo and other files, to pay attention to the Generatorconfig.xml file Javamodelgenerator, such as several nodes Targetproject attribute configuration, where I have written the absolute path. In fact, if this configuration goes wrong and you write a folder that does not exist, a warning prompt appears.
And using Java program to run MyBatis generator 1.3.x, directly copy the code given on this site.
The reference URL is as follows: http://generator.sturgeon.mopaas.com/running/runningWithJava.html
Finally, my development environment: Ubuntu Kylin + ECLIPSE-LUNA-SR2 + jdk8