Re: Loading FTL templates from JAR in maven

Daniel Dekany <[email protected]> Thu, 26 Dec 2013 11:47:46 +0100
Newsgroups gmane.comp.web.freemarker.devel
Message-ID <[email protected]>
Again, check if you can access the resource purely with "core" Java.
That is, with ClassLoader.getResource. If you can't, FreeMarker can't
either.

The jar name surely shouldn't occur in the template name, as that's
not how Java's class loading mechanism works. FreeMarker just uses
that.

-- 
Thanks,
 Daniel Dekany


Wednesday, December 25, 2013, 4:26:02 PM, Vijay wrote:

> Hi Daniel,
>
> Th eproblem I have is the controller class which I am using is in a
> package(com.test.freemarker) and the template jar file is loaded from
> repository by defining in pom.xml. So the template JAR file is available
> under maven dependencies in my STS.
> After complete application build the controller class file is in different
> jar and template files are in different jar. 
>
> PFB the code snippet. 
>
> Configuration Class in  com.test.freemarker package.
>
> protected Configuration createConfiguration() {
>
>     config = super.createConfiguration();
>     config.setClassForTemplateLoading(getClass(), "/");
>     
>     return config;
> }
>
> There are multiple folders in template JAR in which I need to traverse to
> get the template file. 
>
> Code snippet for reading template file:
>
> try{
>
> Template template = getConfiguration().getTemplate("/<template jar
name>>/WEB-INF/freemarker/sample.ftl");
>
> } catch(Exception e) {
>
> }
> In this case I am getting file not found. 
> Also I tried loading using various combinations by not providing the jar
> name etc.,.
> But nothing seems to work. 
> Can you please help me in resolving this. 
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/Loading-FTL-templates-from-JAR-in-maven-tp4654896p4654904.html
> Sent from the freemarker-devel mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT
> organizations don't have a clear picture of how application performance
> affects their revenue. With AppDynamics, you get 100% visibility into your
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> _______________________________________________
> FreeMarker-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk