Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a JAR with the source code in Maven

Tags:

How can I use Maven 2.2 to generate a JAR with the source code inside it?

like image 287
Kaltresian Avatar asked Jan 24 '12 19:01

Kaltresian


People also ask

How do I create a source jar?

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.

How do I ask Maven to generate a jar from my project?

In order to compile the project into an executable jar, please run Maven with mvn clean package command.

What is source jar?

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.


2 Answers

mvn source:jar 

This is using the source:jar plugin documentation

Usage documentation

like image 129
stacker Avatar answered Oct 07 '22 22:10

stacker


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.

like image 41
Dave Newton Avatar answered Oct 07 '22 22:10

Dave Newton