maven中mybatis-generator自定义插件,无法实例化的问题
- 问题描述
Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.6:generate failed: Cannot instantiate object of type [你的自定义插件路径]
- 问题解决
需要把对应的插件类打包成jar,然后再把打包好的jar安装到本地maven库中,添加到插件的依赖中:
- maven将jar包安装到本地仓库的方法:
mvn install:install-file -Dfile=【jar包的路径】 -DgroupId=【你的groupid】 -DartifactId=【你的artifactid】 -Dversion=【你的版本号】 -Dpackaging=jar
mvn install:install-file -Dfile=E://MavenRep//mybatis_generator_plugs.jar -DgroupId=cn.zanezz -DartifactId=commnetgenerator -Dversion=1.0.0 -Dpackaging=jar
该依赖要放到插件的依赖中,否则会出现同样的问题
<dependency>
<groupId>cn.zanezz</groupId>
<artifactId>commnetgenerator</artifactId>
<version>1.0.0</version>
</dependency>
或者直接在插件如下代码
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<!--配置文件的位置-->
<configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.6</version>
</dependency>
<dependency>
<groupId>groupId</groupId>
<artifactId>mybatis_generator_plugs</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>E:\MavenRep\mybatis_generator_plugs.jar</systemPath>
</dependency>
</dependencies>
</plugin>