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:
- If you need to generate a separate JAR with your sources, see the Maven Sources plugin: http://maven.apache.org/plugins/maven-source-plugin/
- Also take a look at this related StackOverflow discussion