相关疑难解决方法(0)

在java中加载freemarker模板时出现FileNotFoundException

即使模板实际存在于路径中,我在加载freemarker模板时也会收到文件未找到异常.

更新:这是作为Web服务运行的.它将根据搜索查询将xml返回给客户端.当我从另一个java程序(来自静态main)调用它时,模板加载成功.但是当客户端请求xml时,会发生FileNotFoundException.

操作系统:Windows 7文件的绝对路径:C:/ Users/Jay/workspace/WebService/templates /

这是我的代码:

private String templatizeQuestion(QuestionResponse qr) throws Exception
{
    SimpleHash context = new SimpleHash();
    Configuration config = new Configuration();

    StringWriter out = new StringWriter();

    Template _template = null;

    if(condition1)
    {           
        _template = config.getTemplate("/templates/fibplain.xml");
    } 
    else if(condition2)
    {
        _template = config.getTemplate("/templates/mcq.xml");
    }
    context.put("questionResponse", qr);
    _template.process(context, out);

    return out.toString();
 }
Run Code Online (Sandbox Code Playgroud)

完整错误堆栈:

 java.io.FileNotFoundException: Template /templates/fibplain.xml not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:495)
at freemarker.template.Configuration.getTemplate(Configuration.java:458)
at com.hm.newAge.services.Curriculum.templatizeQuestion(Curriculum.java:251)
at com.hm.newAge.services.Curriculum.processQuestion(Curriculum.java:228)
at com.hm.newAge.services.Curriculum.processQuestionList(Curriculum.java:210)
at com.hm.newAge.services.Curriculum.getTest(Curriculum.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) …
Run Code Online (Sandbox Code Playgroud)

java eclipse freemarker filenotfoundexception

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

eclipse ×1

filenotfoundexception ×1

freemarker ×1

java ×1