eclipse - FileNotFoundException when loading freemarker template in java -



eclipse - FileNotFoundException when loading freemarker template in java -

i file not found exception while loading freemarker template though template nowadays in path.

update: running webservice. homecoming xml client based on search query. template loads when phone call java program(from static main). when client requests xml, filenotfoundexception occurs.

os: windows 7 absolute path of file: c:/users/jay/workspace/webservice/templates/

here code:

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); homecoming out.tostring(); }

full error stack:

java.io.filenotfoundexception: template /templates/fibplain.xml not found. @ freemarker.template.configuration.gettemplate(configuration.java:495) @ freemarker.template.configuration.gettemplate(configuration.java:458) @ com.hm.newage.services.curriculum.templatizequestion(curriculum.java:251) @ com.hm.newage.services.curriculum.processquestion(curriculum.java:228) @ com.hm.newage.services.curriculum.processquestionlist(curriculum.java:210) @ com.hm.newage.services.curriculum.gettest(curriculum.java:122) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.apache.axis2.rpc.receivers.rpcutil.invokeserviceclass(rpcutil.java:212) @ org.apache.axis2.rpc.receivers.rpcmessagereceiver.invokebusinesslogic(rpcmessagereceiver.java:117) @ org.apache.axis2.receivers.abstractinoutmessagereceiver.invokebusinesslogic(abstractinoutmessagereceiver.java:40) @ org.apache.axis2.receivers.abstractmessagereceiver.receive(abstractmessagereceiver.java:114) @ org.apache.axis2.engine.axisengine.receive(axisengine.java:181) @ org.apache.axis2.transport.http.httptransportutils.processhttppostrequest(httptransportutils.java:172) @ org.apache.axis2.transport.http.axisservlet.dopost(axisservlet.java:146) @ javax.servlet.http.httpservlet.service(httpservlet.java:637) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293) @ org.apache.coyote.http11.http11processor.process(http11processor.java:861) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(unknown source)

freemarker template paths resolved templateloader object, should specify in configuration object. path specify template path interpreted templateloader, , relative kind of base of operations directory (even if starts /), that's called template root directory reason. in example, haven't specified templateloader, using default templateloader, there backward-compatibility, , useless (and dangerous). so, this:

config.setdirectoryfortemplateloading(new file( "c:/users/jay/workspace/webservice/templates"));

and then:

config.gettemplate("fibplain.xml");

note /template prefix not there now, template path relative c:/users/jay/workspace/webservice/templates. (this means template can't out of ../-s, can of import security.)

instead of loading real directory, can load templates serlvetcontext, "class path", etc. depends on templateloader choosing.

see also: http://freemarker.org/docs/pgui_config_templateloading.html

update: if filenotfoundexception instead of templatenotfoundexception, it's time upgrade freemarker @ to the lowest degree 2.3.22. gives improve error messages, if typical error of using default templateloader, tells right in error message. less wasted developer time.

java eclipse freemarker filenotfoundexception

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -