Java – Changing default file structure in a Java Struts App

configuration-filesjavastrutstemplates

I have been working with Struts for some time, but for a project I am finishing I was asked to separate Templates (velocity .vm files), configs (struts.xml, persistence.xml) from main WAR file.

I have all in default structure like:

    application
    |-- META-INF            -- Some configs are here
    |-- WEB-INF             -- others here
    |   |-- classes
    |   |   |-- META-INF
    |   |   `-- mypackage
    |   |       `-- class-files
    |   `-- lib
    |-- css
    `-- tpl                 -- Template dir to be relocated

And I apparently can't find documentation about how to setup (probably in struts.xml) where my templates go, and where config files will be.

I think I will have to use configurations on the application server too (I am using Jetty 5.1.14).

So, any lights on how to configure it ?

Thanks


Well, the whole thing about changing templates place is to put the templates in a designer accessible area, so any modification needed, the designer can load them to his/her computer, edit, and upload it again. I think this is a common scenario. So, probably I am missing something in my research. Maybe I am focusing in configuring it on the wrong place … Any thoughts ?

Best Answer

If I understood your question about Struts config files right, they are specified in web.xml. Find the Struts servlet config param. The param-value can be a list of comma separated list of XML files to load. Eg:

<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
            WEB-INF/config/struts-config.xml,
            WEB-INF/config/struts-config-stuff.xml,
            WEB-INF/config/struts-config-good.xml,
            WEB-INF/config/struts-config-bad.xml,
            WEB-INF/config/struts-config-ugly.xml
        </param-value>
    </init-param>
    ...
</servlet>

See this Struts guide under 5.3.2. And yes, this applies to 2.x also.