集成mybatis-generator-maven-plugin报错A required class was missing while ..org/mybatis/generator/api/dom

景靖琪
2023-12-01

背景

集成mybatis-generator-maven-plugin时,出现的问题和找到的解决办法分享;

  • spring-boot-2.0.0.RELEASE
  • mybatis-generator-maven-plugin-1.4.0

问题现象

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< com.itoken:itoken-service-admin >-------------------
[INFO] Building itoken-service-admin 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for com.alibaba:druid:jar:1.1.21 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.4.0:generate (default-cli) @ itoken-service-admin ---
[INFO] Connecting to the Database
[INFO] Introspecting table itoken-service-admin..tb_sys_user
[INFO] Introspecting table itoken-service-posts..tb_posts_post
[INFO] Generating Record class for table itoken-service-admin..tb_sys_user
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.906 s
[INFO] Finished at: 2020-04-04T16:05:15+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate (default-cli) on project itoken-service-admin: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate failed: A required class was missing while executing org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0:generate: org/mybatis/generator/api/dom/xml/Element
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.mybatis.generator:mybatis-generator-maven-plugin:1.4.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/chenym/software/maven/repository/org/mybatis/generator/mybatis-generator-maven-plugin/1.4.0/mybatis-generator-maven-plugin-1.4.0.jar
[ERROR] urls[1] = file:/Users/chenym/software/maven/repository/mysql/mysql-connector-java/8.0.19/mysql-connector-java-8.0.19.jar
[ERROR] urls[2] = file:/Users/chenym/software/maven/repository/com/google/protobuf/protobuf-java/3.6.1/protobuf-java-3.6.1.jar
[ERROR] urls[3] = file:/Users/chenym/software/maven/repository/tk/mybatis/mapper/4.1.5/mapper-4.1.5.jar
[ERROR] urls[4] = file:/Users/chenym/software/maven/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar
[ERROR] urls[5] = file:/Users/chenym/software/maven/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar
[ERROR] urls[6] = file:/Users/chenym/software/maven/repository/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar
[ERROR] urls[7] = file:/Users/chenym/software/maven/repository/org/eclipse/sisu/org.eclipse.sisu.inject/0.3.3/org.eclipse.sisu.inject-0.3.3.jar
[ERROR] urls[8] = file:/Users/chenym/software/maven/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[9] = file:/Users/chenym/software/maven/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
[ERROR] urls[10] = file:/Users/chenym/software/maven/repository/org/mybatis/generator/mybatis-generator-core/1.4.0/mybatis-generator-core-1.4.0.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] : org.mybatis.generator.api.dom.xml.Element
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/PluginContainerException

问题本质

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.itoken.service.admin.ServiceAdminApplication</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.4.0</version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.19</version>
                    </dependency>
                    <dependency>
                        <groupId>tk.mybatis</groupId>
                        <artifactId>mapper</artifactId>
                        <version>4.1.5</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

解决办法

降低该插件版本
mybatis-generator-maven-plugin_1.3.7

推测是版本不兼容 

<plugin>
     <groupId>org.mybatis.generator</groupId>
     <artifactId>mybatis-generator-maven-plugin</artifactId>
     <version>1.3.7</version>
</plugin>

参考 https://www.520mwx.com/view/26731 

 类似资料: