项目目录结构:
代码:
public class Generator {
public void excute() {
try {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
File configFile = new File("." + File.separator + "generatorConfig.xml");
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
System.out.println("开始生成文件...");
myBatisGenerator.generate(null);
System.out.println("生成文件完成.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
项目是用来生成mybatis相关文件的,但是一直报错:java.io.FileNotFoundException: generatorConfig.xml (系统找不到指定的文件。)
编译时,resources中的文件不是已经在classes下了吗,为什么?该怎么改?
Download the maven project
resources
目录下就是classpath
.You are running the testgenerator under the test package, so filenotfound? If so, please create the java/test/resources directory. You can check your target directory. When running the test program, the configuration file is not generated to the compiled path. Then Naturally, the configuration file cannot be found