java spring-boot:repackage 和 mvn 包的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42921490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between spring-boot:repackage and mvn package
提问by Samuel
After reading Spring documentation and some other articles on web, I am still confused what is the difference between Spring Boot Maven plugin's spring-boot:repackageand a regular mvn package.
在阅读了 Spring 文档和网络上的其他一些文章后,我仍然很困惑 Spring Boot Maven 插件的spring-boot:repackage和常规mvn package之间的区别是什么。
I've thought that mvn package creates a jar with all dependencies included, so what is really the reason to use the plugin by Spring?
我认为 mvn 包创建了一个包含所有依赖项的 jar,那么 Spring 使用该插件的真正原因是什么?
回答by Ananthapadmanabhan
The maven package goal and the spring-boot:repackage goal are differentin nature. The spring-boot repackage goal is mainly intended to make a JAR or WAR executable from the command line itself using java -jar *.jar
while the maven package
goal take the compiled code and package it in its distributable format, such as a JAR.It is the spring-boot repackage goal that repackages the JAR produced by maven to specify the main class and make it executableusing an embedded container.
maven 包目标和 spring-boot:repackage 目标本质上是不同的。spring-boot 重新打包目标主要是为了从命令行本身使用 JAR 或 WAR 可执行文件,java -jar *.jar
而maven package
目标将编译后的代码打包成可分发的格式,例如 JAR。它是 spring-boot 重新打包目标重新打包 maven 生成的 JAR 以指定主类并使用嵌入式容器使其可执行。
Maven Package
Maven 包
The first, and most common way, to set the packaging for your project via the equally named POM element . Some of the valid packaging values are jar, war, ear and pom. If no packaging value has been specified, it will default to jar.
When a package is defined,each packaging contains a list of goals to bind to a particular phase ,the jar packaging will bind the following goals to build phases of the default lifecycle : process-resources,compile,process-test-resources,test-compile,test,package,install,deploy.
第一种也是最常见的方法,通过同名的 POM 元素为您的项目设置打包。一些有效的包装值是 jar、war、ear 和 pom。如果未指定包装值,则默认为 jar。
当定义一个包时,每个包都包含一个绑定到特定阶段的目标列表,jar 包将绑定以下目标来构建默认生命周期的阶段:process-resources,compile,process-test-resources,test-编译、测试、打包、安装、部署。
Spring-boot:repackage
Spring-boot:重新打包
Plugin to be included is :
要包含的插件是:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The configuration repackages a jar or war that is built during the package phase of the Maven lifecycle.
该配置重新打包在 Maven 生命周期的打包阶段构建的 jar 或 war。
So,Once spring-boot-maven-plugin has been included in your pom.xml, it automatically tries to rewrite archives to make them executable by using the spring-boot:repackage goal. You should configure your project to build a jar or war (as appropriate) by using the usual packaging element.
因此,一旦 spring-boot-maven-plugin 已包含在您的 pom.xml 中,它会自动尝试使用 spring-boot:repackage 目标重写档案以使其可执行。您应该使用常用的包装元素来配置您的项目以构建 jar 或 war(视情况而定)。
Reference : https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
参考:https: //docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
回答by fabfas
Spring repackage a jar or war that is built during the package phase of the Maven lifecycle. The following example shows both the repackaged jar, as well as the original jar, in the target directory:
Spring 重新打包在 Maven 生命周期的打包阶段构建的 jar 或 war。以下示例显示了目标目录中重新打包的 jar 和原始 jar:
$ mvn package
$ ls target/*.jar
target/myproject-1.0.0.jar target/myproject-1.0.0.jar.original
If you don't include the configuration, you can run the plugin on its own (but only if the package goal is used as well). For example:
如果不包含配置,则可以自行运行插件(但前提是也使用了包目标)。例如:
$ mvn package spring-boot:repackage
$ ls target/*.jar
target/myproject-1.0.0.jar target/myproject-1.0.0.jar.original
See more details from spring website using the link
使用链接从 spring 网站查看更多详细信息
回答by PaulNUK
mvn package creates a jar or war.
mvn 包创建一个 jar 或 war。
The spring boot plugin takes that jar or war and repackages them to make them executable from the command line (i.e. no app server needed).
spring boot 插件获取那个 jar 或 war 并重新打包它们,使它们可以从命令行执行(即不需要应用程序服务器)。
From the plugin docs:
从插件文档:
"Repackages existing JAR and WAR archives so that they can be executed from the command line using java -jar."
“重新打包现有的 JAR 和 WAR 存档,以便可以使用 java -jar 从命令行执行它们。”