2 Replies Latest reply on Oct 16, 2011 8:39 AM by Adrien Adrien

    Configure static resources in JBOSS AS 7

    Joydev Singha Newbie

      Hi,

       

      How can I serve static files such as images out of JBOSS AS 7.  Initially I have configured static files which are out of JBOSS AS 4.2.2 in server.xml.

       

      I found that in JBOSS AS 7 the same thing can be done using static-resources in standalone.xml, but I could not find the attributes which would specify the directory location and the alias. Can you please help in configuring the static files which are out of JBOSS.

        • 1. Re: Configure static resources in JBOSS AS 7
          Joydev Singha Newbie

          Can anybody please reply to this.

           

          I have almost ported my application from JBOSS AS4 to JBOSS AS7.

          • 2. Re: Configure static resources in JBOSS AS 7
            Adrien Adrien Apprentice

            I'm not sur it is the best way to do it,  but to ackieve it in AS7.0.2 , actually I've added a directory in  standalone/deployements/mydirectory.war  with an   web.xml in a WEB--INF subdirectory with expiredfilter to define cache-expired.

             

            {code:xml}<?xml version="1.0"?>

            <web-app 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"

                  version="3.0">

            <description>My static resources</description>

            <display-name>My static resources</display-name>

            <filter>

            <filter-name>ExpiresFilter</filter-name>

            <filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>

            <init-param>

                <param-name>ExpiresByType image</param-name>

                <param-value>access plus 1 month</param-value>

            </init-param>

            </filter>

             

             

            <filter-mapping>

            <filter-name>ExpiresFilter</filter-name>

            <url-pattern>/*</url-pattern>

            <dispatcher>REQUEST</dispatcher>

            </filter-mapping>

            </web-app>

            {code}

             

             

            To deploy it you 'll have to add a file of the war name suffixed by '.dodeploy'  at standalone/deployements/mydirectory.war.dodeploy

             

            The you can access to resources like this http://localhost:8080/mydirectory/..../x.png


            If you need to dynamically write in this dir from another .war/.ear then you can write in using

            String pathSeparator = System.getProperty("file.separator");

            String path =System.getProperties().get("jboss.server.base.dir") +pathSeparator+"deployments"+pathSeparator+"mydirectory.war"+pathSeparator+"photos"+pathSeparator;

             

            If I clean standalone/data or your standaline.xml I need to recreate file mydirectory.war.dodeploy to redeploy it

             

            If there is a best solution I'm also interessed to know how to do this.

             

            May be an expert can tell us if it is the best way to store static resources?

             

            Bests regards