Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put struts.xml

With Struts2 we have to have struts.xml in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it under WEB-INF/classes and have it include ../struts2.xml

2 Problems:

  1. Eclipse cleans out the classes folder when I do a rebuild, so it deletes struts.xml
  2. Eclipse doesn't show the classes folder in my project browser, so its a poor place to stick config files in the first place.

How are you Struts2 Eclipse developers doing this?

like image 602
ariso Avatar asked May 15 '09 18:05

ariso


People also ask

Where is struts config xml located?

xml file of the fault module is represented as fault-struts-config. xml and is present in <Web NMS Home>/webclient/fault/conf directory. The configuration file basically contains three main elements: <form-beans>

What is the use of Web xml file in struts?

In the web. xml file, Struts defines its FilterDispatcher, the Servlet Filter class that initializes the Struts framework and handles all requests. This filter can contain initialization parameters that affect what, if any, additional configuration files are loaded and how the framework should behave.

What is struts xml?

The struts. xml file contains the configuration information that you will be modifying as actions are developed. This file can be used to override default settings for an application, for example struts. devMode = false and other settings which are defined in property file.

How many struts xml are supported in an application?

The struts application contains two main configuration files struts. xml file and struts.


2 Answers

You can either just put the struts.xml at the root of your source directory or set up an additional resources source directory and put it there. Eclipse quite happily copies it to WEB-INF/classes for you when it does a compilation.

like image 157
Peter Kelley Avatar answered Nov 23 '22 17:11

Peter Kelley


I am late to the party, we can configure the struts.xml in any directory in the classpath of the web application, but provide the location using the "config" init parameter of the filter configuration in web.xml as below, if my struts.xml file is in "/com/resources/" directory.

   <filter>
        <filter-name>action</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
         <init-param>
            <param-name>config</param-name>
            <param-value>struts-default.xml,struts-plugin.xml,/com/resources/struts.xml</param-value>
         </init-param>
    </filter>

If we don't provide a config init parameter struts2 by default takes 3 values "struts-default.xml,struts-plugin.xml,struts.xml", you can see the struts2 Dispatcher class code below which will configure these 3 files to the configuration manager.

String configPaths = (String)this.initParams.get("config");
if (configPaths == null) {
  configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
}
String[] files = configPaths.split("\\s*[,]\\s*");
for (String file : files)
  if (file.endsWith(".xml")) {
    if ("xwork.xml".equals(file))
      this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
    else
      this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
  }
like image 41
satish nagamalla Avatar answered Nov 23 '22 17:11

satish nagamalla