File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes struts 2.1 config file location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2.1 config file location" Watch "struts 2.1 config file location" New topic
Author

struts 2.1 config file location

jake khan
Greenhorn

Joined: Feb 18, 2009
Posts: 3
hi

i'm trying to configure struts 2.1 so that it finds my struts config file under /WEB-INF/config/, but for some reason this is proving more difficult than what i thought it would be.

what i have tried so far is:

1) put the config file in the root of my java sources dir, which means that when i build my project (in eclipse) the file is copied to the classes dir and is thereby automatically put on the classpath. doing it this way means it's enough to put the following in web.xml:

<filter>
<filter-name>struts2</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, struts-config.xml</param-value>
</init-param>
</filter>

2) do the above (1), and in a more or less empty struts-config.xml have an <include /> element, trying to include a second struts config file with the bulk of the config stuff from /WEB-INF/config/, but i seem to not be able to get the include to find the second file despite trying absolute and relative paths, leading and non-leading slash etc.

3) do the above (1), but instead of just struts-config.xml put /WEB-INF/config/struts-config.xml

4) doing the above (1), but have a second <init-param> block and specify the struts-config.xml file there. the first <init-param> block would only have the first two values, struts-default.xml and struts-plugin.xml. i wasn't quite sure what the param-name should be though, and i havent been able to find out what the valid init parameters are for StrutsPrepareAndExecuteFilter.


any help would be appreciated. this really shouldn't be very hard, and it's quite possible that im missing something obvious

thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Off the top of my head I thought that the S2 config files had to be on the classpath, but I could be mis-remembering. Is it really important for you that they not be on the classpath?
jake khan
Greenhorn

Joined: Feb 18, 2009
Posts: 3
I mainly want to have all config files in the one place, eg under /WEB-INF/config/.
I guess I can keep it there, and, as part of the build, add an extra step to copy it to the classes dir.
Cheers,
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, they're all in one place if they're in the classpath, too.
jake khan
Greenhorn

Joined: Feb 18, 2009
Posts: 3
yes. makes more sense to me to have config files in a config directory, rather than in a java source directory...
i'll fiddle around with a build script and see if i can work it out.
thanks for your feedback
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The thing is that having them on the classpath allows for more versatility, in that JAR files (like plugins, portions of apps, etc.) can contain trivially-loadable config files.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2.1 config file location