mybatis-generator-maven-plugin:1.3.7:generate failed: Exception getting JDBC Driver: com.mysql.jdbc.

唐恺
2023-12-01

使用Maven :generator插件自动生成pojo以及xml映射文件时报这个错:

[ERROR] Failed to execute goal org.mybatis.generator:
mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project demo: 
Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate failed: 
Exception getting JDBC Driver: com.mysql.jdbc.Driver -> [Help 1]

解决方法:

<plugins>

            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <configuration>
                    <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
              
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.42</version>
                    </dependency>
                </dependencies>

            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>

在plugin中添加mysql-connector-java的dependency,可以得到解决:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.3.7:generate (default-cli) @ demo ---
[INFO] Connecting to the Database
[INFO] Introspecting table sys_user
[INFO] Generating Record class for table sys_user
[INFO] Generating Mapper Interface for table sys_user
[INFO] Generating SQL Map for table sys_user
[INFO] Saving file SysUserMapper.xml
[INFO] Saving file SysUser.java
[INFO] Saving file SysUserMapper.java
[WARNING] Existing file D:\epean\homework\exampleManage\src\main\java\com\cpown\demo\pojo\SysUser.java was overwritten
[WARNING] Existing file D:\epean\homework\exampleManage\src\main\java\com\cpown\demo\mapper\SysUserMapper.java was overwritten
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.882 s
[INFO] Finished at: 2020-07-14T20:27:10+08:00
[INFO] Final Memory: 23M/224M
[INFO] ------------------------------------------------------------------------

成功了.

 类似资料: