Badr DRAIFI
Badr DRAIFI

Reputation: 335

class.getResource returns a wrong path of my file

I want to use Velocity to template my emails, but i struggled to give the right path of my template : "template.vm" that in my resource folder created by maven.

I used : class.getResource("template.vm").getPath => but getResource retruns null wich is logique cause as i know template.vm in that case should be in the same package of the class, and my template.vm is on WEB-INF/classes

So i used : class.getResource("/template.vm").getPath, but it returns a wrong path, in my case the path of template.vm is : D:/folderOne/FolderTwo/WEB-INF/classes/template.vm and getResource retruns : /D:/folderOne/FolderTwo/WEB-INF/classes/template.vm what makes velocity class to throw : Unable to find resource with the given path : /D:/folderOne/FolderTwo/WEB-INF/classes/template.vm

I am struggling with this little probleme more then a day now, please help.

Upvotes: 0

Views: 747

Answers (1)

Loša
Loša

Reputation: 2621

You should use ClassPathResourceLoader instead of FileResourceLoader for your Velocity. If you use it, you can simply call VelocityEngine.getTemplate("template.vm").

Upvotes: 1

Related Questions