在idea中使用mybatis generator执行后没生成相关代码也没任何控制台文件输出

  •       解决处理

 建立一个warningList并传递给MyBatisGeneratorjava

List<String> warnings = new ArrayList<>();
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, null, warnings);

前面你们都会注意,可是就是没有输出warnings(List)。输出便可看到错误提示信息shell

if (warnings.isEmpty()) {
     System.out.println("MyBatis文件生成成功!!");
 } else {
     System.err.println(warnings);
 }
  • 缘由

    mybatis generator出现异常不是抛出,而是进行捕获放在传入warnings(List)里面,若是你不传递的话,它会初始化一个,可是在结束时并不会输出任何信息。mybatis

    开始和你们同样没有输出List,而后一步步断点调试,发如今最后写入文件的时候没有找到路径。例如在MyBatisGenerator.class源码中你会发现捕获的异常处理的状况eclipse

private void writeGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback callback)
        throws InterruptedException, IOException {
    File targetFile;
    String source;
    try {
        File directory = shellCallback.getDirectory(gjf
                .getTargetProject(), gjf.getTargetPackage());
        targetFile = new File(directory, gjf.getFileName());
        if (targetFile.exists()) {
            if (shellCallback.isMergeSupported()) {
                source = shellCallback.mergeJavaFile(gjf
                        .getFormattedContent(), targetFile,
                        MergeConstants.OLD_ELEMENT_TAGS,
                        gjf.getFileEncoding());
            } else if (shellCallback.isOverwriteEnabled()) {
                source = gjf.getFormattedContent();
                warnings.add(getString("Warning.11", //$NON-NLS-1$
                        targetFile.getAbsolutePath()));
            } else {
                source = gjf.getFormattedContent();
                targetFile = getUniqueFileName(directory, gjf
                        .getFileName());
                warnings.add(getString(
                        "Warning.2", targetFile.getAbsolutePath())); //$NON-NLS-1$
            }
        } else {
            source = gjf.getFormattedContent();
        }

        callback.checkCancel();
        callback.startTask(getString(
                "Progress.15", targetFile.getName())); //$NON-NLS-1$
        writeFile(targetFile, source, gjf.getFileEncoding());
    } catch (ShellException e) {
        warnings.add(e.getMessage());
    }
}

下面是输出的错误信息maven

[The specified target project directory .\src/main/java does not exist]
  • 最后 

    提示是路径不存在,在配置文件中填写的是相对路径;有点奇怪,同事使用eclipse就能够使用相对路径,可是我用idea就不行,以前使用maven插件是能够使用相对路径的ide

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.7</version>
    <configuration>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
    </configuration>
</plugin>
相关文章
相关标签/搜索