Search code examples
glassfishglassfish-3

How do I make alternatedocroot work in glassfish 3.1.2?


I'm trying to get my page resources and uploaded files out of the proyect working folder (working with JSF 2 and in Netbeans IDE 7.2) so I did not know how to access them, so i started to read how to do it and I have found the "alternatedocroot"... I have been trying to get it work creating the glassfish-web file (because it was not created) and putting the property leaving my glassfish-web.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <property name="alternatedocroot_1" value="from=/images/* dir=d:/Plataforma_RAQ-Recursos/3D" />
</glassfish-web-app>

and my web.xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>faces/inicio.xhtml</welcome-file>
</welcome-file-list>

<context-param>  
    <param-name>primefaces.THEME</param-name>  
    <param-value>sunny</param-value>  
</context-param>

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>


</web-app>

what else do i need to get it working ?, what I am missing ?, is there anything more to do than putting the path in the glassfish-web.xml ?


Solution

  • I finally solved it thanks to this post: http://www.marceble.com/2009/07/virtual-directories-in-glassfish/

    So, resuming,

    1. if you do not have the glassfish-web.xml you can create it by yourself via the menu File > New File > Glassfish > Glassfish Descriptor.

    2. your xml should be like this :

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE glassfish-web-app PUBLIC 
      "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
       "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
      <glassfish-web-app error-url="">
          <parameter-encoding default-charset="UTF-8" />
          <!-- Here is the problem, you should have your path of "dir" to the 
          containing folder you wish to share, so in "from" you set the name of the 
          folder and that is all, you should be able to access to the contents of
          the folder -->
          <property name="alternatedocroot_1" value="from=/media/* dir=D:\" />
          <!-- in this case, the contaning folder is D:\ and the folder to share is 
          "media" so the requests to "localhost:8080/MyApplication/media/" should 
          redirect to D:\media\ -->
      </glassfish-web-app>