-->

Path of struts.xml and web.xml

2019-06-25 05:13发布

问题:

When I use eclipse to develop struts2. I found the struts.xml file can be put in src folder or WebContent\WEB-INF\classes. Both paths are ok.

What's the difference? what's better? Does different path affect the performance or other thing? Is there any other path for struts.xml file?

And the web.xml only can be put in WebContent\WEB-INF ? Or any other path for web.xml?

回答1:

  1. From the web app's standpoint, there's no difference: struts.xml is expected to be at the root of the classpath after deployment. How and when it gets there is irrelevant.

  2. Putting the config file in the source directory is better, because you shouldn't need to manage the class directory itself. Tools like Maven move artifacts from a project's src/main/resources directory to the classpath. It won't move an XML file from src/main/java unless specifically configured to do so.

  3. No.

  4. You may override the default location. There's rarely a good reason to; so don't. If you're using multiple config files it's fine to put them in packages, but I'd leave them on the classpath.

  5. That's a totally unrelated question, but it should stay in the default location, WEB-INF. WebContent is project-specific (Eclipse)–you'd need to configure the deployment/packaging process to find it.