Maintain configuration files in a resource folder or Java package
The default struts.xml file is loaded from the root of the classpath. In a web application, the WEB-INF/classes folder is loaded to the root of the classpath.
To avoid maintaining files directly under WEB-INF, create a resource folder that can be copied to WEB-INF/classes when the appliication is compiled. If subfolders are also copied, then the resource folder can mirror the Java package system. The Struts Showcase application uses this common approach.
+ java + receivables - Deposit.java - Menu.java + payables - Menu.java + resources - payables.xml - receivables.xml - struts.xml + payables - Menu.properties + receivables - Menu.properties + webapp + payables + receivables - Deposit-error.jsp - Deposit-input.jsp + WEB-INFAlternatively, maintain the configuration files alongside the Java packages, and have the build system copy resource files from the Java source root. The Struts Mailreader uses this alternative approach. + java + receivables - struts.xml - Deposit.java - Menu.java - Menu.properties + payables - struts.xml - Menu.java - Menu.properties - struts.xml + webapp + receivables - Deposit-error.jsp - Deposit-input.jsp + payables + WEB-INFIf FreeMarker templates are used in lieu of JSPs, then all the resources for a namespace can be kept in a single folder.
+ java + receivables - struts.xml - Deposit.java - Deposit-input.ftl - Deposit-error.ftl - Menu.java - Menu.properties + payables - struts.xml - Menu.java - Menu.properties - struts.xmlHTH, Ted.
Ted Husted is a software engineer and team mentor. His specialty is building agile web applications with open source products like Yahoo! User Interface Library, Struts, Spring, iBATIS, and MySQL, for either Java or Microsoft .NET, and helping others do the same.
Copyright Ted Husted 2007. All rights reserved.