In maven how can I include non-java src files in the same place in the output jar?

后端 未结 3 1800
时光取名叫无心
时光取名叫无心 2020-12-01 15:18

I received a source code bundle. Inside the src directory tree there are some properties files(.properties) which I want to keep in the output jar in the same place. e.g: I

相关标签:
3条回答
  • 2020-12-01 16:01

    With this pom fragment you include anything that is not a java file for both main and test artifact:

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
    </build>
    
    0 讨论(0)
  • 2020-12-01 16:05

    Include and mix all your non .java src files and the src/main/resources:

    <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>${project.build.sourceDirectory}</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
    
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>${project.build.testSourceDirectory}</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
    
    0 讨论(0)
  • 2020-12-01 16:10

    You could add the following in your pom indicating that the resources are available in src/main/java and including the type of resources.

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>
    
    0 讨论(0)
提交回复
热议问题