Daniel Dekany
2014-07-29 19:24:44 UTC
The problem is that cfg doesn't load templates from an absolute file
paths. It loads them from a virtual file system that you should
specify to cfg, but you haven't, so it uses the default one that you
just shouldn't ever use (backward compatibility burden...). Since you
want to load templates from plain files (as opposed to from classpath,
etc), you should add:
cfg.setDirectreyForTemplateLoader(new File(absolutePath))
The path passed to getTemplate will *always* be interpreted relatively
to this directory.
Note that if you don't need template caching and templates loading
each other, you can also just use `new Template(name, reader, cfg)`
instead of cfg.getTemplate.
--
Thanks,
Daniel Dekany
paths. It loads them from a virtual file system that you should
specify to cfg, but you haven't, so it uses the default one that you
just shouldn't ever use (backward compatibility burden...). Since you
want to load templates from plain files (as opposed to from classpath,
etc), you should add:
cfg.setDirectreyForTemplateLoader(new File(absolutePath))
The path passed to getTemplate will *always* be interpreted relatively
to this directory.
Note that if you don't need template caching and templates loading
each other, you can also just use `new Template(name, reader, cfg)`
instead of cfg.getTemplate.
--
Thanks,
Daniel Dekany
Hi!
I´m having a problem with my template when I execute my java.jar in a unix
cron.
When I try my jar out of the cron...
I´ve no problem.
But when I execute it inside the cron... I get a FileNotFoundException.
I´ve tried all the paths possibles, but it doesn´t work.
The template (and all prefolders has enough permissions to the template).
U know if its a bug? I´m doing anything wrong?
This is the code where I call the template... (I´ve changed it so I could
try paths sending it by parameter)
Configuration cfg = new Configuration();
Template template = null;
try{
template =
cfg.getTemplate("/templates/emailTemplate.ftl");
}
catch (IOException ioe)
{
try{
template = cfg.getTemplate(path+"/emailTemplate.ftl");
}
catch (IOException ioe2)
{System.out.println(ioe2.toString());
}
}
my template is in the path /u01/java/app/templates/emailTemplate.ftl
I´ve tried u01/java/app , /u01/java/app ...
At the begining I´ve the same problem with config.properties... but I could
solve it loading it from the full path
/u01/app/java/resources/config.properties.
But with my template it didn´t work...
Any Idea? Thank you in advance!!
--
http://freemarker.624813.n4.nabble.com/Template-not-found-in-Unix-Crontab-tp4655238.html
Sent from the freemarker-user mailing list archive at Nabble.com.
I´m having a problem with my template when I execute my java.jar in a unix
cron.
When I try my jar out of the cron...
I´ve no problem.
But when I execute it inside the cron... I get a FileNotFoundException.
I´ve tried all the paths possibles, but it doesn´t work.
The template (and all prefolders has enough permissions to the template).
U know if its a bug? I´m doing anything wrong?
This is the code where I call the template... (I´ve changed it so I could
try paths sending it by parameter)
Configuration cfg = new Configuration();
Template template = null;
try{
template =
cfg.getTemplate("/templates/emailTemplate.ftl");
}
catch (IOException ioe)
{
try{
template = cfg.getTemplate(path+"/emailTemplate.ftl");
}
catch (IOException ioe2)
{System.out.println(ioe2.toString());
}
}
my template is in the path /u01/java/app/templates/emailTemplate.ftl
I´ve tried u01/java/app , /u01/java/app ...
At the begining I´ve the same problem with config.properties... but I could
solve it loading it from the full path
/u01/app/java/resources/config.properties.
But with my template it didn´t work...
Any Idea? Thank you in advance!!
--
http://freemarker.624813.n4.nabble.com/Template-not-found-in-Unix-Crontab-tp4655238.html
Sent from the freemarker-user mailing list archive at Nabble.com.