在Eclipse中从Spring:boot项目创建war文件 [英] Create war file from Spring:boot project in Eclipse

查看:236
本文介绍了在Eclipse中从Spring:boot项目创建war文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Spring Boot还是很陌生,并且已经完成了一个在本地主机上运行良好的应用程序.有人告诉我要将其部署在本地主机之外,例如在webbhotel或simular上,我需要将项目导出为war文件而不是jar文件.

I am pretty new to Spring Boot and I have completed a application that works well on my localhost. As I have been told to deploy it outside my localhost on for example a webbhotel or simular I need to export the project as a war-file and not as a jar-file.

更新!! 我将项目作为Spring Initialzr中生成的Springproject来运行,并使用Eclipse作为IDE.

UPDATE!! I run the project as a Springproject generated in Spring Initialzr and using Eclipse as a IDE.

在Eclipse中,我已按照步骤

In Eclipse I have followed the steps

<packaging>war</packaging>

<dependencies>
    <!-- … -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- … -->
</dependencies>

来自Spring Boot参考页 https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

from Spring Boot Referencepage https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

在我的项目中,我使用

<dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

我是否需要添加sprinng-boot-starter-tomcat依赖项,并在tomcat-embed-jasper上添加该依赖项,以便我的依赖项是这样?

Do I need to add the sprinng-boot-starter-tomcat dependency and add provided to that on aswell as tomcat-embed-jasper so that my dependency will be like this?

<dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
     <dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

当我尝试在Eclipse中导出到war文件时,Eclipse找不到我的项目.如果我尝试导出Java> JAR FILE,但如果尝试Web> WAR FILE

When I try to export to war-file in Eclipse, Eclipse can't find my project. It can find it if I try to export Java>JAR FILE but not if I try Web>WAR FILE

有人知道我在做什么错吗?是否有必要导出到WAR文件以部署到外部服务器?

Do anyone know what I am doing wrong and if it is neccesary to export to a WAR-file to deploy to a external server?

推荐答案

您需要在@SpringBootApplication中扩展**** SpringBootServletInitializer ****

You need to extend ****SpringBootServletInitializer**** in your @SpringBootApplication

您无需添加**** sprinng-boot-starter-tomcat ****依赖性即可生成战争文件

You don't need to add the ****sprinng-boot-starter-tomcat**** dependency for war file generation

在pom.xml中使用以下配置

Use below configuration in pom.xml

<packaging>war</packaging>

为您的项目配置构建路径,然后选择JDK

Configure Build Path for your project and select JDK

右键单击项目>运行方式> Maven安装

Right click on project > Run As > Maven Install

它将在目标文件夹中生成war文件.

It will generate the war file inside target folder.

复制此战争并部署到任何Web/应用程序服务器(我将其重命名为demo.war).

Copy this war and deploy to any web/application server (I have renamed it to demo.war).

您可以使用主机名以及端口名和应用程序名称来访问该应用程序.

You can access the app by using your host name followed by the port and app name.

这篇关于在Eclipse中从Spring:boot项目创建war文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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