How to include Java sources in Maven JAR

Problem

You’re using Maven as build system but you need to include your Java sources into your JAR file generated by mvn package.

Solution

Include the following XML code into you pom.xml (inside the project element):

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

If you already have a element in your pom.xml, you need to add everything between and from above right after.

Related problems: