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
\
Use case is pretty straightforward if you ask me. (It seems src/main/config has since been removed standard directory layout)
/src/main/config is intended for assembly plugin where you might construct a zip file:
hello-world.zip
lib/
<dependencies>
bin/
run.bat
run.sh
config/
config.properies
The email exchange at http://www.mail-archive.com/users@maven.apache.org/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.
scr/main/resources
is a place where you put your images, sounds, templates, language bundles, textual and binary files used by the source code. All config files like excache.xml, log4j.properties, logback.xml and others go to src/main/config
.
Add to your pom.xml
:
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<directory>src/main/config</directory>
</resource>
</resources>
</build>
The inclusion of src/main/config
in Maven's standard directory layout has been removed due in part to the confusion caused between src/main/config
and src/main/resources
. This very stackoverflow question is actually referenced in the JIRA ticket for the removal of src/main/config from Maven's standard.
Short answer: Use src/main/resources
not src/main/config
. It's the (new) Maven way.