mybatis-generator的maven插件使用异常(mybatis-generator-maven-plugin):generate failed: Exception getting JDBC Driver

使用mybatis的代码生成工具:mybatis-generator,在父model中引入了maven插件的依赖,如下:

            <!-- Mybatis.generator插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator.version}</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>

子model(dao层)中使用,引入插件:

    <build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

配置generatorConfig.xml文件,开始生成代码,如下操作

mybatis-generator的maven插件使用异常(mybatis-generator-maven-plugin):generate failed: Exception getting JDBC Driver

报错如下:

[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project mf-dao: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate failed: Exception getting JDBC Driver: oracle.jdbc.driver.OracleDriver -> [Help 1]

分析:

很明显的报错,提示找不到DB的驱动jar

设置插件的依赖参数如下:

           <plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<!--可指定配置文件地址,默认地址resources/generatorConfig.xml -->
<!--<configurationFile>${basedir}/src/main/java/com/shengpay/mf/dao/db/generator/generatorConfig.xml</configurationFile>-->
</configuration>
<!--依赖DB的驱动包 -->
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.ojdbc6.version}</version>
</dependency>
<dependency>
<groupId>com.mas.mf</groupId>
<artifactId>mf-dao</artifactId>
<version>${mf.module.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis.generator.version}</version>
</dependency>
</dependencies>
</plugin>

注意:

1、所有引用的外部插件(比如分页插件)或者jar包,必须指定依赖

   比如这里依赖了自己的jar:mf-dao

   在generator之前,必须先生成jar并存放在本地仓库或私服

2、depences下,每个依赖的jar必须指定version

3、如果generatorConfig.xml文件使用了自定义的插件,在指定依赖前,请先编译,确定生成了jar包(不然会报错提示无法初始化该对象)

4、如果generatorConfig.xml没有放在resources下,请指定generatorConfig.xml配置文件的路径

上一篇:ionic 打包 报错Execution failed for task ':processDebugResources'. > com.android.ide.common.process.ProcessException: Failed to execute aapt


下一篇:docker报错:Failed to restart docker.service: Unit not found.