I want to put a configuration file in my Maven project. Looking at the standard directory layout, there are two places that seem sensible, "src/main/resources
" and "src/main/config
". Could someone explain the difference between these, and explain when you would put something in config
and when in resources
?
In this case, the file I'm looking at is ehcache.xml
, but my question isn't ehcache specific, I'm curious for log4j.properties
etc.
A bit of googling discovered this person had the same question, but the answers seemed contradictory, and not very authorative.
src/main/webapp – for web applications, contains resources like JavaScript, CSS, HTML files, view templates, and images. src/main/filters – contains files that inject values into configuration properties in the resources folder during the build phase.
The target directory is used to house all output of the build. The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.
src/main/java places your code that use for real production. src/test/java places your test use case code, like junit test. These codes would be executed when doing maven package things. These codes won't be packaged to your war or jar file.
The email exchange at http://www.mail-archive.com/[email protected]/msg90985.html says:
"This is all theory... Perhaps while writing the docs, someone involved with Maven development thought it might be useful to have a src/main/config directory and so it was included in docs, but since it was never implemented in the code, it is not being used today."
and
"The directory [src/main/config] doesn't show up on the classpath so the application or test classes can't read anything in it."
So just use src/main/resources
.
Note: I don't know if this is true (I'm the question asker), but that would explain why so many people on the web recommend src/main/resources
for log4j.properties. If people agree this is the right answer could you let me know (comment or vote) I put it here to save other people the typing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With