Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to install Spring boot application on Linux system

Shulou Source: shulou.com Published: 2022-06-01 18:12:50 09月13日 Update

This article will explain in detail how to install Spring boot application on Linux system, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

Unix/Linux services

systemd service

operation

1. CentOS 7 virtual machine with JDK installed

Note that when downloading the Linux version of JDK can not be directly downloaded through wget this direct link, otherwise the decompression will not be successful, should open the original official website, click on the permission to click download (this way download is very slow), the better way is to copy the download page address to Thunder, through Thunder to open the download page, agree to the license click download.

After downloading, decompress and configure environment variables

tar -zxvf jdk1.8.0_211.jar.gz

Environment variable configuration: /etc/profile file Finally add the following

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

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

2. Prepare the spring boot application for installation

2.1 For successful installation, pay particular attention to the configuration of plug-ins in the pom file. The correct example is as follows:

org.springframework.boot spring-boot-maven-plugin com.itsherman.dcm.Application true repackage

If you declare only the spring-boot-maven-plugin and ignore the following configuration items, it is likely that your package (jar) port has failed to launch in the past. Error: Main menu attribute not found.

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

General complete file information is as follows:

Manifest-Version: 1.0Archiver-Version: Plexus ArchiverBuilt-By: ShermanStart-Class: com.itsherman.dcm.ApplicationSpring-Boot-Classes: BOOT-INF/classes/Spring-Boot-Lib: BOOT-INF/lib/Spring-Boot-Version: 2.1.5.RELEASECreated-By: Apache Maven 3.6.0Build-Jdk: 1.8.0_172Main-Class: org.springframework.boot.loader.JarLauncher

After that, try executing it locally using java -jar myapp.jar

3. Migrate jar package to virtual machine in step [1] through xftp and other file migration tools

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

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

·Description: Description of the program

·User: System User

·ExecuStart: 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

boot service

systemctl enable myapp.service

View service status information

systemctl status myapp.service

6. test

Open the browser and access the service.

About "how to install Spring boot application on Linux system" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Files services configuration information programs variables environment systems applications success articles migrations commands tools plug-ins folders ways more problems face-to-face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Shulou Technology OPPO Reno vpn