简体   繁体   中英

What's the difference between Maven Jar Plugin and Maven Source Plugin?

I was reading about how to create a jar file with Maven, but I saw some pom.xml files using Maven Source Plugin and others using Maven Jar Plugin.

In the Apache Maven Project page I found these descriptions:


This plugin provides the capability to build jars. If you like to sign jars please use the Maven Jarsigner Plugin.



The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.


Reading these descriptions, I stayed in doubt about when use one or other plugin, and what are the differences or benefits, because I understood that both make the same thing.

  • The Apache Maven JAR Plugin is used to build jar files containing .class files in order to distribute applications or libraries in bytecode format.

  • The Apache Maven Source Plugin is used to build jar files containing source files (.java files) in order to allow IDE to show the source code when debugging. This jar file is used in combination with the jar file containing .class files.

maven jar plugin

The jar plugin creates a JAR file from your Maven project. The jar goal of the jar plugin is bound to the package phase of the Maven default lifecycle. When you type mvn clean install, Maven will execute all the phases in the default lifecycle up to and including the install phase, which also includes the package phase.

maven source plugin

The source plugin creates a JAR file with the project source code. It defines five goals: aggregate, jar, test-jar, jar-no-fork, and test-jar-no-fork. All these five goals of the source plugin will run under the package phase of the default lifecycle.

Unlike any of the plugins we discussed before, if you want to execute the source plugin with the Maven default lifecycle, it has to be defined in the project POM file, shown as follows. The super POM file does not define the source plugin; it has to be within your Maven project itself

What is the Difference

Both create JAR files; however, the jar plugin creates a JAR file from the binary artifact, while the source plugin creates a JAR file from the source code. Small-scale open source projects use this approach to distribute the corresponding source code along with the binary artifacts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM