Detailed tutorial on installing Spring boot applications on Linux systems

Detailed tutorial on installing Spring boot applications on Linux systems

Unix/Linux Services

systemd services

Operation process

1. CentOS7 virtual machine with JDK installed

Please note that when downloading the Linux version of JDK, you cannot download it directly through a direct link such as wget, otherwise the decompression will fail. You should open the original official website, click to agree to the license and then click to download (this method downloads very slowly). A better way is to copy the download page address to Thunder, open the download page through Thunder, and click to download after agreeing to the license.

After downloading, unzip and configure environment variables

tar -zxvf jdk1.8.0_211.jar.gz

Environment variable configuration: Add the following to the /etc/profile file

export JAVA_HOME=/var/java/jdk1.8.0_211
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

After adding the environment variables, execute source /etc/profile to make the environment variables take effect.

2. Prepare the spring boot application to be installed

2.1 To install successfully, pay special attention to the configuration of the relevant plug-ins in the pom file. The correct example is as follows:

<build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
     <mainClass>com.itsherman.dcm.Application</mainClass>
     <executable>true</executable>
    </configuration>
    <executions>
     <execution>
      <goals>
       <goal>repackage</goal>
      </goals>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>

If you only declare spring-boot-maven-plugin plugin and ignore the subsequent configuration items, it is likely that the package (jar) you built will not start successfully after being ported. Reports an error that the main menu attribute cannot be found.

The above problem is mainly because there is a META_INF folder in the built executable jar package. The MANIFEST.MF file in this folder describes the main information of the package, and the Main-Class line is missing. The solution is that we can add it manually, or follow the above configuration, especially the execution configuration item cannot be missing, and then re-execute mvn install. After regenerating the jar package, open it with the winrar tool and check the information of the MANIFEST.MF file.

The general complete file information is as follows:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Sherman
Start-Class: com.itsherman.dcm.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 2.1.5.RELEASE
Created-By: Apache Maven 3.6.0
Build-Jdk: 1.8.0_172
Main-Class: org.springframework.boot.loader.JarLauncher

After that, you can try to execute it locally using the java -jar myapp.jar command

3. Use file migration tools such as xftp to migrate the jar package to the virtual machine in step [1]

4. Write the service configuration file under /etc/systemd/system on the virtual machine. The reference example is as follows:

[Unit]
Description=myapp
After=syslog.target
[Service]
User=hadoop
ExecStart=/var/java/jdk1.8.0_211/bin/java -jar /home/hadoop/myapp/dev-manager.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

•Description: Description of the program
•User: System user
•ExecStart: The command to start the program

After writing the configuration file, save and exit

. Start the service

Refresh service configuration information

systemctl daemon-reload

Start the service

systemctl start myapp.service

Start service at boot

systemctl enable myapp.service

View service status information

systemctl status myapp.service

6. Testing

Open the browser and access the service

Summarize

The above is a detailed tutorial on how to install Spring boot applications on Linux systems. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to package and deploy springboot to linux server
  • How to run springboot in the background of linux
  • Methods and steps to deploy springboot project under Linux
  • Deploy Spring Boot program using Linux
  • Detailed explanation of spring boot linux startup method

<<:  Detailed explanation of the use of Gulp.js, a powerful tool for front-end task construction

>>:  MySQL replication advantages and principles explained in detail

Recommend

How to implement a binary search tree using JavaScript

One of the most commonly used and discussed data ...

MySQL slow query pt-query-digest analysis of slow query log

1. Introduction pt-query-digest is a tool for ana...

Solve the problem of inconsistent MySQL storage time

After obtaining the system time using Java and st...

Summary of Problems in Installing MySQL 5.7.19 under Linux

The first time I installed MySQL on my virtual ma...

js implements the pop-up login box by clicking the pop-up window

This article shares the specific code of js to re...

Understanding Vuex in one article

Table of contents Overview Vuex four major object...

React example of how to get the value of the input box

React multiple ways to get the value of the input...

XHTML introductory tutorial: text formatting and special characters

<br />This section introduces how to impleme...

Detailed examples of ajax usage in js and jQuery

Table of contents Native JS How to send a get req...

MySQL briefly understands how "order by" works

For sorting, order by is a keyword we use very fr...

JavaScript Canvas draws dynamic wireframe effect

This article shares the specific code of JavaScri...

Linux completely removes node.js and reinstalls it through the yum command

first step Delete it once with the built-in packa...