In maven, what is the difference between main/resources and main/config?

前端 未结 4 1086
失恋的感觉
失恋的感觉 2020-12-24 10:48

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\

相关标签:
4条回答
  • 2020-12-24 11:28

    Use case is pretty straightforward if you ask me. (It seems src/main/config has since been removed standard directory layout)

    • /src/main/resources go on into jar and thus on classpath
    • /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
      
    0 讨论(0)
  • 2020-12-24 11:31

    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.

    0 讨论(0)
  • 2020-12-24 11:37

    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>
    
    0 讨论(0)
  • 2020-12-24 11:38

    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.

    0 讨论(0)
提交回复
热议问题