waffel’s Weblog

Juni 25, 2008

Reuse facelets xhtml files and taglibs from jar archives

Filed under: JSF,software,Uncategorized — Thomas Wabner @ 4:47 pm
Tags: ,

I have asked myself, if it is possible to use facelets xhtml files and taglibs from a jar file instead from the whole web application.

The short anwser: Yes, it is possible 😉

The facelets documentation gives a hint how to use the tag lib from a jar file. But you cannot found in the documentation, if it is possible also to use a xhtml file (referenced from the taglib for example). Of course facelets uses the same approach to load xhtml files from a jar file as for the tag library.

The follow tag lib definition is placed in my JAR project under /META-INF/myProject.taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"





The select.xhtml file is placed in the same project under /META-INF/components/select.xhml and contains some facelets definitions (ui component with a selectbox fo example). The point is, that facelets searches the jar archive under the /META-INF directory for the xhtml file.

Now you can simple use the tag in you web application. You only need to include the jar file with the tag library and xhtml file in you web application classpath.

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns="http://www.w3.org/1999/xhtml"

Update: See comments. I have created a small example.


11 Kommentare »

  1. Hi Thomas,

    I try to reuse facelets templates from an jar file, too. I didn’t manage to this. Would It be possible to publish an example.jar?

    Thanks in advance,


    Kommentar von achim — Juni 26, 2008 @ 3:12 pm | Antworten

  2. I have created the example. It contanis an jar file (facelet-embedded) and a war file (facelet-example). The war file simple uses the jar file.

    It runs in tomcat6 without problem.

    You can download the file here:


    I have created the projects with maven and the myfaces facelets arachetype. But the approach works also with SUN RI and facelets.

    Kommentar von thomaswabner — Juni 27, 2008 @ 1:25 pm | Antworten

  3. Hi Thomas,
    do you know how a JavaScript-File (or a image, etc.), which is also included in the jar, must be referenced in the *.xhtml to work.

    Thanks in advance,

    Kommentar von Kai — Oktober 28, 2008 @ 11:02 am | Antworten

  4. Hi Kai,

    currently I have not testet, how to include other resources in the JAR. If I have some time, I will have a look.


    – waffel

    Kommentar von Thomas Wabner — November 25, 2008 @ 10:18 am | Antworten

  5. […] Reuse facelets xhtml files and taglibs from jar archives « waffel’s Weblog (tags: jsf facelets) […]

    Pingback von links for 2009-06-10 « sySolution — Juni 10, 2009 @ 5:01 pm | Antworten

  6. Hi Thomas,

    Nice article!
    Have you tried to include resources (js, css or images…) in the JAR file ?
    Where should I put resources in the jar and how to reference it inside my facelet page?

    – Mehul

    Kommentar von Mehul Soni — September 17, 2009 @ 8:17 am | Antworten

    • Hi Thomas,

      thank you for this article!
      Have you tried to include resources (js, css or images…) in the JAR file ?
      Where should I put resources in the jar and how to reference it inside my facelet page?


      Kommentar von abdellah — Februar 4, 2010 @ 10:38 am | Antworten

  7. Hi Waffel,

    from a realworld project … we’are using this feature to share „common“ templates between web-apps. The first time this was cool. But now where we have to change things, search for error etc. this method reduce the performance of our development-team.

    For example, I have a common site-template. Know I will have a look into the template to find the defined „ui:insert“’s. How can I search these „jar-packaged templates“?

    At the moment I have no idea to joins these two aspects a) share common templates b) easy develop. 😀

    So my recommendations for such facelets-sharing:

    1. define a structure in your project, each project should use the same directory-structure to store facelets-stuff – so searching is easy
    2. share only finished stuff into common modules – if you don’t you are in a development-hell 😉


    Kommentar von Andreas Höhmann — Februar 11, 2010 @ 12:33 pm | Antworten

  8. This works but I trying to load dinamic facelets, from diferents jars:

    I defined some facelets:

    components/select1.xhtml (tag select1)
    components/select2.xhtml (tag select2)

    In my xhtml I have:

    miBean.dynamicComponent return an UIComponent:

    UIComponent containerComponent = new HtmlAjaxOutputPanel();


    So my question is How can I add „components/select#.xhtml“ as a child of the containerComponent ?

    Kommentar von Luis — April 9, 2010 @ 2:32 pm | Antworten

  9. […] Reuse facelets xhtml files and taglibs from jar archives facelets, Java, jsf, Programação […]

    Pingback von Criando e compartilhando componentes Facelets — Juli 23, 2010 @ 1:06 pm | Antworten

  10. Hi,
    I am struggling with something similar for quite some time.
    Basically I want to put an xhtml file inside a jar file and use it from a navigation rule


    I want to be able to place tha dummy.xhtml file inside a jar file.
    Has anybody managed to accomplish something similar?

    Kommentar von Dan Corneanu — November 29, 2010 @ 10:02 am | Antworten

RSS feed for comments on this post. TrackBack URI

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

Erstelle kostenlos eine Website oder ein Blog auf WordPress.com.

%d Bloggern gefällt das: