java - Velocity's FileResourceLoader can't find resources -


i use velocity in order load email templates. templates first downloaded ftp server , saved temporary files.

however, when try load template exception: org.apache.velocity.exception.resourcenotfoundexception: unable find resource 'c:\users\someusername\appdata\local\temp\template1526050996884865454.html'

and i'm sure file there , it's not damaged.

that's how try load template:

template = velocityengine.gettemplate(tempfile.getcanonicalpath());

here's velocity.properties file load (and i've checked properties initialized!)

file.resource.loader.class=org.apache.velocity.runtime.resource.loader.fileresourceloader file.resource.loader=file file.resource.loader.path=. 

so lies problem? because appdata folder hidden default?

i think there's design flaw in velocity fileresourceloader. if file.resource.loader.path other empty string, it'll mangle absolute paths handed file. additionally has unix/linux-specific code "nip off" (paraphrasing actual code comment) absolute file-path handed (giving broken absolute path re-rooted current path setting).

solution 1: set file.resource.loader.path empty string (prior init()) , use absolute file-paths file parameter

ve.setproperty("file.resource.loader.path", ""); ve.init(); template template = ve.gettemplate("c:\\users\\someusername\\appdata\\local\\temp\\template1526050996884865454.html"); 

solution 2: set path common root temp files , hand paths relative that:

ve.setproperty("file.resource.loader.path", "c:\\users\\someusername\\appdata\\local\\temp"); ve.init(); template template = ve.gettemplate("template1526050996884865454.html"); 

ultimately think fileresourceloader class better if detected absolute path handed file-name , not try mash path setting it.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -