This article is a mirror article of machine translation, please click here to jump to the original article.

View: 23452|Reply: 0

[Source] Docker deploys war applications to Tomcat containers

[Copy link]
Posted on 10/24/2021 9:24:35 PM | | | |
I created a new Spring Boot project using Eclipse and wanted to deploy it to Tomcat in the form of a war package. Directly through the IDE tool, it can be started normally, as shown in the figure below:



How do I package a Maven project into a war package?

Modify the pom.xml file

Find the project node and add the following configuration:



At the dependencies node, spring-boot-starter-tomcat is introduced at the bottom, as follows:

spring-boot-starter-tomcat is modified toprovidedto avoid conflicts with independent tomcat containers, which means that provided is only used when compiling and testing, and is gone when packaged.

Alias the project, find the build node, and addfinalNameThe configuration is as follows:


If you don't add it, the project name is your artifactId-version, and the generated war package name is also artifactId-version.war (e.g., demo-1-0.0.1-SNAPSHOT.war), and the project name is too long when the browser accesses it.

Create a ServletInitializer file, inheriting from SpringBootServletInitializer, and override the configure method as follows:

Compile and package

Packaged via maven command, the command is as follows:

From the target directory, you can view the generated war packages, as shown in the following figure:



Deploy to a Docker container

First, create a /data/webapps folder on the host machine with the following command:

Start a tomcat container with the following command:

Upload itsvse.war under the /data/webapps folder and access it through your browser:http://192.168.50.227:8888/itsvse/home/test, as shown in the figure below:



(End)






Previous:The CentOS system initializes some basic settings
Next:The ServletRequest and HttpServletRequest interfaces in Java
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com