Spring Boot Maven 插件不创建可执行 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26314374/
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
Spring Boot Maven Plugin not creating executable jar
提问by Bransomis Bailout
My POM is as below. But the executable JAR is not being create when I run "mvn clean package". However, when I remove the dependencyManagement element and add spring boot as parent POM, everything works.
我的 POM 如下。但是当我运行“mvn clean package”时没有创建可执行JAR。但是,当我删除 dependencyManagement 元素并将 spring boot 添加为父 POM 时,一切正常。
What am I missing?
我错过了什么?
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>sample-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2.0.M2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
回答by Piotr Kochański
You need to configure spring-boot-maven-plugin by yourself:
需要自己配置spring-boot-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.1.8.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Obviously set your own plugin version. Now if you run mvn install or mvn package you'll have executable JAR generated.
显然设置您自己的插件版本。现在,如果您运行 mvn install 或 mvn package,您将生成可执行的 JAR。
回答by Dave Syer
That's because the plugin is configured in the parent in the second case. If you want to manage your own plugins (ie not use the parent), you have to explicitly configure the spring boot plugin (and others).
那是因为在第二种情况下插件是在父级中配置的。如果要管理自己的插件(即不使用父插件),则必须显式配置 spring boot 插件(和其他插件)。
回答by mladirazvijac
When you using Spring boot dependency management (without spring-boot-starter-parent) you can still keep the benefit of the dependency management, but not the plugin management.
当您使用 Spring boot 依赖管理(没有 spring-boot-starter-parent)时,您仍然可以保留依赖管理的好处,但不是插件管理。
That means that you need to provide full plugin (with version and other stuff).
这意味着您需要提供完整的插件(包括版本和其他内容)。
回答by Tom Chamberlain
Spring Boot will make sure your application will boot as a test when you run mvn package. Make sure it is not failing during this.
Spring Boot 将确保您的应用程序在您运行mvn package. 确保它在此期间没有失败。
回答by Riddhi Gohil
Given is pom.xmlto create an executable jar file
给出的是pom.xml来创建一个可执行的 jar 文件
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.executablejar</groupId>
<artifactId>demo</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demo Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.8</java-version>
<docker.image.prefix>springDemo</docker.image.prefix>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>demo</finalName>
</build>
To create executable jar, type following command
要创建可执行 jar,请键入以下命令
$ mvn clean
$ mvn install
Watch video :https://youtu.be/Yy8RxjdcTfE
观看视频:https : //youtu.be/Yy8RxjdcTfE
回答by Anand
According SpringBoot Document. The plugin rewrites your manifest, and in particular it manages the Main-Class and Start-Class entries, so if the defaults don't work you have to configure those there (not in the jar plugin). The Main-Class in the manifest is actually controlled by the layout property of the boot plugin
根据 SpringBoot 文档。该插件重写您的清单,特别是它管理 Main-Class 和 Start-Class 条目,因此如果默认值不起作用,您必须在那里配置它们(不在 jar 插件中)。manifest中的Main-Class其实是由boot插件的layout属性控制的
SpringBoot Maven-plugin-not-creating-executable-jar
SpringBoot Maven-plugin-not-creating-executable-jar
Below changes as per SpringBoot docs worked for me.
根据 SpringBoot 文档的以下更改对我有用。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>YourSpringBootJavaClass</mainClass>
<layout>WAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>yourwarfileName</finalName>
</build>
回答by pink spikyhairman
I had been building a runnable JAR (Maven POM) for a project for over a year and recently something changed and the JAR no longer contained any dependency JARs. Eventually, updating to latest Spring boot release (1.5.2.RELEASE for me at the time of writing) resolved the issue.
我已经为一个项目构建了一个可运行的 JAR (Maven POM) 一年多了,最近发生了一些变化,JAR 不再包含任何依赖 JAR。最终,更新到最新的 Spring boot 版本(在撰写本文时对我来说是 1.5.2.RELEASE)解决了这个问题。

