java 使 Spring Tool Suite 生成的 Web 应用程序在独立的 Tomcat 服务器上运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12448874/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:55:37  来源:igfitidea点击:

Making Spring Tool Suite generated web app work on standalone Tomcat server

javaspringtomcatweb-config

提问by prosseek

From Deploying spring web apps using Spring Tool Suitequestion, I could build and deploy spring web application with Spring Tool Suite. I could access the app at localhost:8080/manolitomvc.

使用 Spring Tool Suite问题部署 spring web 应用程序,我可以使用 Spring Tool Suite构建和部署 spring web 应用程序。我可以在localhost:8080/manolitomvc.

enter image description here

在此处输入图片说明

Shutting down the Spring Tool Suite Tomcat server, I relaunch Tomcat with sudo startup.sh, but I got this error message.

关闭 Spring Tool Suite Tomcat 服务器后,我使用 重新启动 Tomcat sudo startup.sh,但收到此错误消息。

enter image description here

在此处输入图片说明

What's wrong? What server setup is necessary for making manolitomvcapp to work?

怎么了?使manolitomvc应用程序运行需要什么服务器设置?

ADDED/SOLVED

添加/解决

Based on Ralph's answer, I could make it work.

根据拉尔夫的回答,我可以让它发挥作用。

In STS workspace directory, I could generate the war file in Tomcat directory.

在 STS 工作区目录中,我可以在 Tomcat 目录中生成 war 文件。

enter image description here

在此处输入图片说明

Copying the war file in the web apps make the deployment work. Interestingly, the manolitomvcdirectory is generated automatically with the action of copying.

复制 web 应用程序中的 war 文件使部署工作。有趣的是,该manolitomvc目录是通过复制操作自动生成的。

enter image description here

在此处输入图片说明

Or, you can just set the destination to the webapp directory.

或者,您可以将目标设置为 webapp 目录。

enter image description here

在此处输入图片说明

采纳答案by Ralph

STS/Eclipse use a complete different (lets call it) "working directory" for tomcat.

STS/Eclipse 为 tomcat 使用一个完全不同的(让我们称之为)“工作目录”。

If you want to run your application without STS/Eclipse, than let STS/Eclipse or Mave create a war file for your project.

如果你想在没有 STS/Eclipse 的情况下运行你的应用程序,那么让 STS/Eclipse 或 Mave 为你的项目创建一个 war 文件。

  • for maven it is: mvn package- it creates a war file in the target folder
  • for STS+Maven it is: Project/Run as.../Maven Package
  • for Eclipse without Maven: Project/Export/Web/WAR file
  • 对于 maven,它是:mvn package- 它在目标文件夹中创建一个 war 文件
  • 对于 STS+Maven,它是:Project/Run as.../Maven Package
  • 对于没有 Maven 的 Eclipse:项目/导出/Web/WAR 文件

Then you need to copy this war file into the webappsfolder of your ORIGINAL tomcat installation (NOT the folder .metadata/plugins/org.eclipse.wst.server.core...within your eclipse workspace direcory)

然后,您需要将此 war 文件复制到webapps原始 tomcat 安装的文件夹中(不是.metadata/plugins/org.eclipse.wst.server.core...eclipse 工作区目录中的文件夹)

回答by Cyber

For the app to run outside of STS or to generate a deployable .warfile install maven on your computer and add the below to your pom.xml

为了使应用程序在 STS 之外运行或生成可部署.war文件,请在您的计算机上安装 maven 并将以下内容添加到您的 pom.xml

pom.xml:

pom.xml:

<packaging>war</packaging>preferable at the beginning under the <version>0.0.1-SNAPSHOT</version>reference.

<packaging>war</packaging>最好在开头下<version>0.0.1-SNAPSHOT</version>参考。

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
</build>

at the very end of your file, this will add the maven plugin to your project.

在文件的最后,这会将 maven 插件添加到您的项目中。

Once Maven is installed, you can navigate to your project within you terminal cd /path/to/projectand run mvn installthis will generate a .warfile with having a 0.0.1-SNAPSHOTadded to your app name, you can rename and drop the war file anywhere you run your server.

安装 Maven 后,您可以在终端中导航到您的项目cd /path/to/project并运行mvn install这将生成一个.war文件,其中0.0.1-SNAPSHOT添加了您的应用程序名称,您可以重命名并删除运行服务器的任何位置的 war 文件。

回答by P Satish Patro

Just go inside your project directory(where src, pom.xml etc are located) in command line. And type

只需在命令行中进入您的项目目录(src、pom.xml 等所在的位置)。并输入

mvn package

mvn package

It will build and generate WAR file for you inside '/target' folder

它将在“ /target”文件夹中为您构建和生成 WAR 文件