You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Frans Thamura <fr...@meruvian.org> on 2008/03/03 00:39:30 UTC

Putting Template inside .jar

hi all,

i need all your idea.

i have 2 project that using struts, the project name is cimande and papaje.

this is the scenario

cimande is the core, and papaje need cimande to run,

cimande need struts2, spring, and hibernate

both spring and hibernate both no problem, i have
applicationContext-cimande.xml for cimande and
applicationContext-papaje.xmlfor papaje,

we put applicationContext-* in /WEB-INF

I successfully put struts' code inside a jar, but the template still in
WEB-INF/view/*

anyone can share the skill

how to call the template inside a jar in struts development. so I can put
all the code in one jar, and can be use in another project, and we still
know, the template inside the jar.


F

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
>> It looks like the templatePath init param is used only by the
>> FileTemplateLoader though. (I've never needed to use that param)
>>
>> The classpath loader uses
>> Thread.currentThread().getContextClassLoader().getResource(resourceName);
>> (and a few other variations if unsuccessful)
>>
>>     
>
> i am try to develop a small code and hope can answer this :)
>
> still blank about how the template in classpath work :)
>
> new world
>
>   

Have a look at org.apache.struts2.views.freemarker.StrutsClassTemplateLoader

and  com.opensymphony.xwork2.util.ClassLoaderUtil

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
>
> It looks like the templatePath init param is used only by the
> FileTemplateLoader though. (I've never needed to use that param)
>
> The classpath loader uses
> Thread.currentThread().getContextClassLoader().getResource(resourceName);
> (and a few other variations if unsuccessful)
>

i am try to develop a small code and hope can answer this :)

still blank about how the template in classpath work :)

new world

F

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
>  do this mean that struts2 automatically search template, when the template
> is not in the /web-inf/view , the struts2 will search in the classpath. is
> this right?
>   
Yes. 

Struts 2 configures a FreeMarker TemplateLoader that:
  - searches the filesytem templatePath if specified 
(FileTemplateLoader); then
  - searches the webapp (WebappTmplateLoader); then
  - searches the classpath

It looks like the templatePath init param is used only by the 
FileTemplateLoader though. (I've never needed to use that param)

The classpath loader uses 
Thread.currentThread().getContextClassLoader().getResource(resourceName);
(and a few other variations if unsuccessful)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
On Mon, Mar 3, 2008 at 8:34 AM, Jeromy Evans <
jeromy.evans@blueskyminds.com.au> wrote:

> The Struts FreemarkerResult and Struts 2 tags explicitly access a
> Freemarker template engine that's setup via the Struts container.
>
> Your example below references the FreemarkerServlet provided by
> Freemarker that's an distinct instance of the template engine.
> You don't require the FreemarkerServlet to serve Freemarker pages via
> Struts.  You can use it to serve Freemarker pages directly (without
> struts).
>
> You can use both at the same time, just note that they're separate.
> There's no glue AFAIK.
>
> (Although as you're using spring you may be get them to both use the
> same bean, but I'm not sure about that).
>

 do this mean that struts2 automatically search template, when the template
is not in the /web-inf/view , the struts2 will search in the classpath. is
this right?

NB: i still dont know how to put in spring bean now ...

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
The Struts FreemarkerResult and Struts 2 tags explicitly access a 
Freemarker template engine that's setup via the Struts container.

Your example below references the FreemarkerServlet provided by 
Freemarker that's an distinct instance of the template engine. 
You don't require the FreemarkerServlet to serve Freemarker pages via 
Struts.  You can use it to serve Freemarker pages directly (without struts).

You can use both at the same time, just note that they're separate.  
There's no glue AFAIK.

(Although as you're using spring you may be get them to both use the 
same bean, but I'm not sure about that).

Frans Thamura wrote:
> hi jeromy,
>
> i have several velocity template inside and i want to put in the jar also
>
> i got this is the syntax to implement TemplatePath (below)
>
> i dont get the relationship between freemarker and struts
>
> because in my strutx.xml's package i just change the result to freemarker,
> and .... done, the template engine is freemarker.
>
> can give the glue
>
>
> this is the freemarker template
>
>
>
>
> <servlet>
>   <servlet-name>freemarker</servlet-name>
>   <servlet-class>*freemarker.ext.servlet.FreemarkerServlet*</servlet-class>
>
>   <!-- FreemarkerServlet settings: -->
>   <init-param>
>     <param-name>TemplatePath</param-name>
>     <param-value>/</param-value>
>   </init-param>
>   <init-param>
>     <param-name>NoCache</param-name>
>     <param-value>true</param-value>
>   </init-param>
>   <init-param>
>     <param-name>ContentType</param-name>
>     <param-value>text/html</param-value>
>   </init-param>
>
>   <!-- FreeMarker settings: -->
>   <init-param>
>     <param-name>template_update_delay</param-name>
>     <param-value>0</param-value> <!-- 0 is for development only! Use
> higher value otherwise. -->
>   </init-param>
>   <init-param>
>     <param-name>default_encoding</param-name>
>     <param-value>ISO-8859-1</param-value>
>   </init-param>
>   <init-param>
>     <param-name>number_format</param-name>
>     <param-value>0.##########</param-value>
>   </init-param>
>
>   <load-on-startup>1</load-on-startup>
>
> </servlet>
>
>   
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.516 / Virus Database: 269.21.3/1307 - Release Date: 2/03/2008 3:59 PM
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
hi jeromy,

i have several velocity template inside and i want to put in the jar also

i got this is the syntax to implement TemplatePath (below)

i dont get the relationship between freemarker and struts

because in my strutx.xml's package i just change the result to freemarker,
and .... done, the template engine is freemarker.

can give the glue


this is the freemarker template




<servlet>
  <servlet-name>freemarker</servlet-name>
  <servlet-class>*freemarker.ext.servlet.FreemarkerServlet*</servlet-class>

  <!-- FreemarkerServlet settings: -->
  <init-param>
    <param-name>TemplatePath</param-name>
    <param-value>/</param-value>
  </init-param>
  <init-param>
    <param-name>NoCache</param-name>
    <param-value>true</param-value>
  </init-param>
  <init-param>
    <param-name>ContentType</param-name>
    <param-value>text/html</param-value>
  </init-param>

  <!-- FreeMarker settings: -->
  <init-param>
    <param-name>template_update_delay</param-name>
    <param-value>0</param-value> <!-- 0 is for development only! Use
higher value otherwise. -->
  </init-param>
  <init-param>
    <param-name>default_encoding</param-name>
    <param-value>ISO-8859-1</param-value>
  </init-param>
  <init-param>
    <param-name>number_format</param-name>
    <param-value>0.##########</param-value>
  </init-param>

  <load-on-startup>1</load-on-startup>

</servlet>

Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
>
> Resolved/Fixed is good/stable.  It's also dated 2004 so it's safe to
> assume it doesn't apply any more.
> I had a look in FreemarkerManager.java and confirmed the templatePath is
> read from servletContext.getInitParameter("TemplatePath") or
> "templatePath"
>
> thx

working in this :)

hope can patch my cimande project with this feature

amazing steps

F

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
> Jeromy,
>
> i got this
>
> https://issues.apache.org/struts/browse/WW-676
>
> is resolved issue = stable?
>
> Frans
>
>   

Resolved/Fixed is good/stable.  It's also dated 2004 so it's safe to 
assume it doesn't apply any more.
I had a look in FreemarkerManager.java and confirmed the templatePath is 
read from servletContext.getInitParameter("TemplatePath") or "templatePath"


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
Jeromy,

i got this

https://issues.apache.org/struts/browse/WW-676

is resolved issue = stable?

Frans

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
>
> we use velocity and freemarker :)
>
> is it possible?
>   
Good choice.  You're in luck!  The Freemarker Configuration searches for 
templates in your web application first and then in your classpath.
Just place them in the jar and reference them by their classpath.

eg
/views/mypage.ftl

(Don't put them in WEB-INF in a jar...that path has a special meaning 
and it might not work).

Also see the Template Loading section of this page: 
http://struts.apache.org/2.x/docs/freemarker.html

Hope that helps

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Putting Template inside .jar

Posted by Frans Thamura <fr...@meruvian.org>.
>
> Is the template a JSP?  If so, you're stuck.  In the current container
> spec, they must be included in the WAR, not in a JAR.
>
> This is a critical flaw of JSPs and one of the many reasons some
> developers prefer velocity or freemarker pages.
>
> To partially overcome the problem, use your build process to copy the
> JSP's from the source/jar to the location for packaging into war.  That
> way you'll at least have to manage only one copy.
>

we use velocity and freemarker :)

is it possible?

i still searching this ....

can help?

F

Re: Putting Template inside .jar

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Frans Thamura wrote:
>
> how to call the template inside a jar in struts development. so I can put
> all the code in one jar, and can be use in another project, and we still
> know, the template inside the jar.
>
>   

Is the template a JSP?  If so, you're stuck.  In the current container 
spec, they must be included in the WAR, not in a JAR.

This is a critical flaw of JSPs and one of the many reasons some 
developers prefer velocity or freemarker pages.

To partially overcome the problem, use your build process to copy the 
JSP's from the source/jar to the location for packaging into war.  That 
way you'll at least have to manage only one copy.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org