Template not found in Unix Crontab

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Template not found in Unix Crontab

Mori83
This post has NOT been accepted by the mailing list yet.
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!!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Template not found in Unix Crontab

Daniel Dekany
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


Tuesday, July 29, 2014, 10:02:53 AM, Mori83 wrote:

> 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!!
>
>
>
> --
> View this message in context:
> 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.
>


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...