在Eclipse中将Spring Boot应用程序导出为JAR文件 [英] Exporting Spring Boot application as JAR file in eclipse

查看:199
本文介绍了在Eclipse中将Spring Boot应用程序导出为JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中使用Spring STS来创建一个简单的基于Web的spring boot项目。我可以在Eclipse中运行它,但当我尝试将其导出为JAR文件时,我得到:

I'm using the Spring STS in Eclipse to create a simple web-based spring boot project. I can run it fine in Eclipse, but when I try to export it as a JAR file I get:

rg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

我的 public static main void main 位于在 Application.java 中,带有 @SpringBootApplication 注释。

My public static main void mainis located in Application.java, with the @SpringBootApplication annotation.

我已经对所有Maven依赖项进行了一百次双重检查。

I've double checked all the Maven dependencies a hundred times.

我做错了什么?

推荐答案

很可能,你正在使用内置的Eclipse导出器生成你的jar,仅包括该项目中实际生成的目标文件。为了拥有一个胖(独立可执行文件)jar,你需要使用Spring Boot Maven或Gradle插件来重新包装jar。

Most likely, you're using the built-in Eclipse exporter to generate your jar, which only includes the target files actually produced in that project. In order to have a "fat" (standalone executable) jar, you need to use the Spring Boot Maven or Gradle plugin to "repackage" the jar.

首先,make确保您拥有重新包装您的构建设置中包含的目标,然后使用Maven 目标。最简单的方法是从命令行运行 mvn package (您可能需要为您的操作系统安装Maven CLI软件包);您也可以右键单击Eclipse中的POM和Run As以从Eclipse中执行特定的Maven操作。

First, make sure that you have the repackage goal included in your build setup, then use the Maven package target. The simplest way to do this is to run mvn package from the command line (you may need to install the Maven CLI package for your OS); you can also right-click the POM in Eclipse and "Run As" to execute specific Maven operations from within Eclipse.

这篇关于在Eclipse中将Spring Boot应用程序导出为JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆