简体   繁体   English

使用和不使用 Maven 插件为 Maven 项目构建 jar 的区别

[英]Difference between building a jar for a maven project with and without maven plugins

Can anyone explain the difference between building a jar for a maven project with and without maven plugins in pom.xml谁能解释在 pom.xml 中使用和不使用 Maven 插件为 Maven 项目构建 jar 的区别

I know that these plugins are useful in creating jar files in maven.我知道这些插件对于在 maven 中创建 jar 文件很有用。

maven-jar-plugin builds jar
maven-assembly-plugin - builds jar with dependencies, 
maven-shade-plugin - creates a standalone jar with resolved dependencies and resolves the conflicts between resource files that have the same name across the jars.

However i'm able to create a jar by running 'mvn package'command without using any plugin in my pom.xml.但是,我可以通过运行“mvn package”命令来创建一个 jar,而无需在我的 pom.xml 中使用任何插件。 What's difference between this jar and the one generated using maven-jar-plugin.这个 jar 和使用 maven-jar-plugin 生成的那个有什么区别。

Here's my pom.xml这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Demo</groupId>
    <artifactId>Demo</artifactId>
    <name>test</name>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

</project>

A maven project when using 'packaging=jar' uses the 'maven-jar-plugin' under to the hood.使用 'packaging=jar' 的 Maven 项目在底层使用了 'maven-jar-plugin'。 This creates a jar assuming you're following the maven standards.假设您遵循 maven 标准,这将创建一个 jar。 Hence your jar with no customisation.因此你的罐子没有定制。

You can further customise the generated jar using the 'maven-jar-plugin', where you might include extra files etc in the jar.您可以使用“maven-jar-plugin”进一步自定义生成的 jar,您可以在其中在 jar 中包含额外的文件等。

The 'maven-assembly-plugin' allows you to generate tar, zip and other compressed artifacts, with custom files and folder. 'maven-assembly-plugin' 允许您使用自定义文件和文件夹生成 tar、zip 和其他压缩工件。

The 'maven-shade-plugin' allows you to creates a fat jar, which contains all the required 3rd party jars and main class. 'maven-shade-plugin' 允许您创建一个胖 jar,其中包含所有必需的 3rd 方 jar 和主类。 This makes your artifact easily deployable and executable.这使您的工件易于部署和执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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