alternatedocroot glassfish 3.1.2 maven enterprise project using JSF

I can't seem to figure out alternatedocroot. I have looked at other questions on stackoverflow, and at the oracle docs for glassfish (but they are as clear as mud to me).

I have a maven project with web, ejb, ear, and an aggregator/parent module. In the web module/project I have added a glassfish-web.xml file with the following entry:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-// GlassFish Application Server 3.1 Servlet 3.0//EN" "">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <property name="alternatedocroot_1" value="from=/images/* dir=/images " />
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>

I have created an images directory on the root of the Linux box (I'll put it somewhere else once I sort this problem out) and put a "picture.png" file in it. I did a chmod -R 777 /image so permissions should not be an issue.

The welcome.xhtml is this:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""
    Hello World
    <h:graphicImage url="/MyProject-web/images/picture.png" 
             width="960" />

All I see when I run the project is the "Hello World"

This is the URL in the browser when run:


Can someone help me with the property / directory setup / and image url in the xhtml file?


So here's how it works (finally). Took me a while before I found something that I could understand. So I'll try to lay it out like nothing else did.

Let's start with where you have some resource or static content files on disk.


And you have static files you want to include or reference like this:


In the glassfish-web.xml you would put (for two docroots)

<property name="alternatedocroot_1" value="from=/images/* dir=/opt/project/resources" />
<property name="alternatedocroot_2" value="from=/css/* dir=/opt/project/resources" />

In your xhtml file to display an image and link to an external css file you do this:

<h:graphicImage url="images/picture.png" />
<link href="css/screen.css" rel="stylesheet" type="text/css" media="screen, projection" />

You can add other directories under say, the images directory so you have something like:


and just as you would expect you would use it like:

<h:graphicImage url="images/otherimages/anotherpicture.png" />

However it appears that if you try to add a symbolic link to where the other images are, it won't work. i.e. the following won't work (you won't be able to access the images in the "otherimages" symbolically linked directory)

.../resources/images$ ln -s /somedirectorytree/otherimages/ otherimages

Which is too bad. If someone knows if this is really possible (i.e. if I'm mistaken) I'd love to know. Or if there are other tricks rather than resort to hard (coded... for want of a better word) configuration. It would be nice to just be able to add links to other file systems.


As a side note, I thought I would add another helpful tidbit that relates to this. If you want to make sure you get the complete (context) path to your file in the url you can add this in front:

<link href="${facesContext.externalContext.requestContextPath}/

Using an example from above:

<link href="${facesContext.externalContext.requestContextPath}/css/screen.css" rel="stylesheet" type="text/css" media="screen, projection" />

This will ensure you are always looking in the correct path on your server.

Need Your Help

Binding to FontWeight in Silverlight 4 using a value converter

silverlight xaml binding ivalueconverter

I want to compare two versions of various properties and bold one of them if it is not equal to the other. Since SL4 doesn't support MultiBinding I am binding the FontWeight to "." so that the ent...

java encryption API + GUI

java encryption

Is there a windows program that allows users to encrypt a file so that it can be accessed via a Java API programmatically (i.e. to decrypt it in memory)?