Fork me on GitHub

Mybatis-Generate反向生成找不到驱动

Generate反向生成找不到驱动

1.搭建SpringMVC+Mybatis环境

搭建教程 点我

环境基本搭建完成,使用代码生成工具Generate时一致报错,缺少数据库驱动

ybatis-generator-maven-plugin:1.3.3:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver

报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project SSM_CRUD: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.3:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.Driver -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.3:generate (default-cli) on project SSM_CRUD: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.3:generate failed: Exception getting JDBC Driver
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.3:generate failed: Exception getting JDBC Driver
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 21 more
Caused by: 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:733)
at org.mybatis.generator.config.Context.introspectTables(Context.java:618)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:254)
at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:188)
at org.mybatis.generator.maven.MyBatisGeneratorMojo.execute(MyBatisGeneratorMojo.java:199)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 22 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.mybatis.generator.internal.ObjectFactory.internalClassForName(ObjectFactory.java:167)
at org.mybatis.generator.internal.ObjectFactory.externalClassForName(ObjectFactory.java:122)
at org.mybatis.generator.internal.db.ConnectionFactory.getDriver(ConnectionFactory.java:82)
... 29 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

2.原因分析

首先在Meven中虽然已经配置mysql-connector-java,
但是mybatis-generator在连接数据库时使用内部驱动,如果内部
未配置驱动,mybatis-generator是不会去找外部驱动.因此就会包
找不找驱动的异常.

3.解决办法增加内部驱动包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<!--mysql驱动包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
</plugin>
-------------本文结束感谢您的阅读-------------

本文标题:Mybatis-Generate反向生成找不到驱动

文章作者:Li Sai

发布时间:2018年04月18日 - 00:04

最后更新:2018年04月18日 - 00:04

原始链接:https://li123sai.github.io/2018/04/18/Generate反响生成找不到驱动/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

undefined