项目目录结构:
代码:
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下了吗,为什么?该怎么改?
PHP中文网2017-04-18 09:48:24
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("generatorConfig.xml");
巴扎黑2017-04-18 09:48:24
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