53

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 want

src/main/java/com.mycompany/utils/Myclass.java 
src/main/java/com.mycompany/utils/Myclass.properties

to stay the same in the jar:

com.mycompany/utils/Myclass.class 
com.mycompany/utils/Myclass.properties

without needing to add the properties file it to separate resources folder. Is there a way to I tell this to maven?

Paralife
  • 6,116
  • 8
  • 38
  • 64

3 Answers3

75

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>
Reactgular
  • 52,335
  • 19
  • 158
  • 208
Raghuram
  • 51,854
  • 11
  • 110
  • 122
14

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>
Erik van Oosten
  • 1,541
  • 14
  • 16
2

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>
GaRzY
  • 65
  • 1
  • 4