How can I use Maven 2.2 to generate a JAR with the source code inside it?
The source plugin can be used to create a jar file of the project sources from the command line or by binding the goal to the project's build lifecycle. To generate the jar from the command line, use the following command: mvn source:jar.
In order to compile the project into an executable jar, please run Maven with mvn clean package command.
That sources jar is a jar that contains only the source code (the . java files) corresponding to the compiled artifact. It is useful to add it as a source attachment in your IDE, to publish the sources, etc. As it only contains sources, not compiled classes (. class files), it is of no use as a library dependency.
mvn source:jar
This is using the source:jar plugin documentation
Usage documentation
Use the <resources>
element; nutshell:
<build> <...> <resources> <resource> <directory>${basedir}/src/main/resources</directory> </resource> <resource> <directory>${basedir}/src/main/java</directory> </resource> </resources> <...> </build>
Edit: Oh, I thought you meant you wanted a single jar with both normal jar contents and the source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With