- 编译出错
This program comes with ABSOLUTELY NO WARRANTY
Exception in thread "main" freemarker.template.TemplateNotFoundException: Template not found for name "dao.ftl".
The name was interpreted by this TemplateLoader: ClassTemplateLoader(resourceLoaderClass=de.greenrobot.daogenerator.DaoGenerator, basePackagePath="/").
at freemarker.template.Configuration.getTemplate(Configuration.java:1833)
at freemarker.template.Configuration.getTemplate(Configuration.java:1646)
at de.greenrobot.daogenerator.DaoGenerator.<init>(DaoGenerator.java:65)
at de.greenrobot.daogenerator.gentest.ExampleDaoGenerator.main(ExampleDaoGenerator.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
需要修改DaoGenerator 的构造函数
public DaoGenerator() throws IOException {
System.out.println("greenDAO Generator");
System.out.println("Copyright 2011-2015 Markus Junginger, greenrobot.de. Licensed under GPL V3.");
System.out.println("This program comes with ABSOLUTELY NO WARRANTY");
patternKeepIncludes = compilePattern("INCLUDES");
patternKeepFields = compilePattern("FIELDS");
patternKeepMethods = compilePattern("METHODS");
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
// 改为绝对路径
// config.setClassForTemplateLoading(this.getClass(), "/");
config.setDirectoryForTemplateLoading(new File("F:\ChinaEle\DownloadSource\greenDAO-master\DaoGenerator\src-template"));
templateDao = config.getTemplate("dao.ftl");
templateDaoMaster = config.getTemplate("dao-master.ftl");
templateDaoSession = config.getTemplate("dao-session.ftl");
templateEntity = config.getTemplate("entity.ftl");
templateDaoUnitTest = config.getTemplate("dao-unit-test.ftl");
templateContentProvider = config.getTemplate("content-provider.ftl");
}
DaoExampleGenerator生成类文件出错,找不到路径,修改
public class ExampleDaoGenerator {
public static void main(String[] args) throws Exception {
Schema schema = new Schema(1000, "de.greenrobot.daoexample");
addNote(schema);
addDevice(schema);
addCustomerOrder(schema);
// 改成绝对路径
// new DaoGenerator().generateAll(schema, "../DaoExample/src/main/java");
new DaoGenerator().generateAll(schema, "F:\\ChinaEle\\DownloadSource\\greenDAO-master\\DaoExample\\src-gen");
}
...
}