] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin Cannot instantiate object of type

[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project com-zhianchen-pgsql: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate failed: Cannot instantiate object of type com.xxx.MybatisCommonGenerator -> [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/PluginExecutionException

Process finished with exit code 1
 
因为重写了commentGenerator类,需要自定义执行
 
 
package com.zhianchen.pgsql;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shensr
 * @version V1.0
 * @description 通过java方式启动mbg,实现自定配置注解,使用maven方式会出现问题
 * @create 2019/10/9
 **/

public class Generator {
    public static void main(String[] args)  {
        List<String> warnings = new ArrayList<String>();
        try {
            // true:生成的文件覆盖之前的
            boolean overwrite = true;
            // 读取配置,构造 Configuration 对象.
            // 如果不想使用配置文件的话,也可以直接来 new Configuration(),然后给相应属性赋值.
            File configFile = new File("src\\main\\resources\\generator\\MygeneratorConfig-pgsql.xml");
            ConfigurationParser cp = new ConfigurationParser(warnings);
            Configuration config = cp.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            myBatisGenerator.generate(null);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        }

        for (String warning : warnings){
            System.out.println(warning);
        }
    }
}

 

posted @ 2024-08-03 23:30  ☆♂安♀★  阅读(13)  评论(0编辑  收藏  举报