A detailed tutorial on installing Spring and boot applications on Linux systems

  • 2021-01-19 22:43:59
  • OfStack

Unix/Linux service

systemd service

The operation process

1. ES11en7 virtual machine of JDK is installed

Note version download linux JDK cannot directly through wget this direct link to download, can extract the otherwise is not successful, should open the original website, click agree to license and then click the download download very slow (this way), a better way is to copy the download page address to the thunderbolt, by opening the thunderbolt download page, agreed to license and then click the download.

After downloading, unzip and configure the environment variables

tar -zxvf jdk1.8.0_211.jar.gz

The environment variable configuration: /etc/profile file is finally added as follows


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. Have the spring boot application ready to install

2.1 For a successful installation, pay particular attention to the configuration of the plugin in the pom file. Correct examples are 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 just declare it spring-boot-maven-plugin Plugins, ignore the following configuration items, then it is likely that the package you built (ES43en) porting did not start successfully in the past. The main menu property error could not be found.

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

The 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

Once you have a problem, you can try using it locally java -jar myapp.jar Execute the command 1

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

4. In a virtual machine /etc/systemd/system The following is the configuration file for the service. Reference examples are 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

The & # 8226; Description: Description information for the program
The & # 8226; User: System user
The & # 8226; ExecStart: The command to start the program

Once you have written the change configuration file, save and exit

. Start the service

Refresh the service configuration information

systemctl daemon-reload

Start the service

systemctl start myapp.service

Boot up service

systemctl enable myapp.service

View service status information

systemctl status myapp.service

Test 6.

That is, open a browser and access the service

conclusion


Related articles: