Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make your Spring Boot project run on the Linux server

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to make your Spring Boot project run on the Linux server, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1 build Linux server 1.1 purchase Ali cloud server or install virtual machine

The suggestion here is CentOS 7.x or CentOS 8.x. Of course, other Linux such as deepin and Ubuntu can also be used, but the installation package and installation mode of the software environment are different, and the running events are all the same.

1.2 install JDK1.8 (CentOS 8 as an example)

Download the JDK installation package:

Https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

Select: jdk-8u291-linux-x64.tar.gz

Installation:

[root@xxx local] # tar-zxvf jdk-8u291-linux-x64.tar.gz [root@xxx local] # vim / etc/profile

Modify the environment variable:

Export JAVA_HOME=/usr/local/jdk1.8.0_291export JER_HOME=$ {JAVA_HOME} / jreexport CLASSPATH=.:$ {JAVA_HOME} / lib:$ {JRE_HOME} / lib:$CLASSPATHexport JAVA_PATH=$ {JAVA_HOME} / bin:$ {JRE_HOME} / binexport PATH=$PATH:$ {JAVA_PATH}

Refresh the configuration file and view the installation results:

[root@xxx local] # source / etc/profile [root@xxx local] # java-versionjava version "1.8.0mm 291" Java (TM) SE Runtime Environment (build 1.8.0_291-b15) Java HotSpot (TM) 64-Bit Server VM (build 25.291-b15, mixed mode) 1.3 install MySQL

Refer to this article: https://www.yisu.com/article/229781.htm

1.4 install Maven (not necessary)

Why is it not necessary to install Maven?

Because Java has cross-platform features, it can be packaged into Jar files or war files in Windows environment, and can also be run directly on Linux!

The purpose of Linux installing Maven is:

Compile and package the project, of course, you can also run it directly

Installation steps:

Download the Maven installation package:

Https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz

Unzip and modify the configuration file on Linux:

[root@xxx local] # tar-zxvf apache-maven-3.8.1-bin.tar.gz [root@xxx local] # vim / etc/profile

Modify the environment variable:

Export MAVEN_HOME=/opt/apache-maven-3.8.1export PATH=$MAVEN_HOME/bin:$PATH

Refresh the configuration file and verify:

[root@xxx local] # source / etc/profile [root@xxx local] # mvn-vApache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: / opt/apache-maven-3.8.1Java version: 1.8.000141, vendor: Oracle Corporation, runtime: / usr/local/jdk1.8.0_141/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux", version: "4.18.0-193.14.2.el8_2.x86_64", arch: "amd64" Family: "unix"

Don't forget! Maven configures Ali Cloud image:

[root@xxx apache-maven-3.8.1] # pwd/opt/apache-maven-3.8.1 [root@xxx apache-maven-3.8.1] # vim conf/settings.xml

It's about the 140th line:

Alimaven central aliyun maven https://maven.aliyun.com/repository/public alimaven central aliyun maven http://maven.aliyun.com/nexus/content/repositories/central/ repo1 central Human Readable Name for this Mirror. Http://repo1.maven.org/maven2/ repo2 central Human Readable Name for this Mirror. Http://repo2.maven.org/maven2/ 2 project deployment runs 2.1 Project compilation and packaging (packaged as a jar file in Windows environment)

There are generally two ways to compile and package a project.

(1) package the project directly in IDEA

(2) use command line mode

Use cmd in a directory that contains pom.xml files

Execute the mvn clean package command

This means success, and then you will find that there is an extra target directory and an jar file.

The above two processes are the same under Linux! (provided that Linux also has Maven installed)

2.2 deployment and operation

(1) method 1: it can be in the case of not compiling to a Jar file

Cd to the home directory of the project you need to run, the directory of the pom.xml file

[root@xxx placard_demo] # ll-rw-r--r-- 1 root root 10519 May 27 08:17 placard_demo.iml-rw-r--r-- 1 root root 5989 May 27 08:17 pom.xml-rw-r--r-- 1 root root 1366 Apr 1 22:36 README.mddrwxr-xr-x 4 root root 30 Apr 1 10:21 srcdrwxr-xr-x 5 root root 61 May 27 14:24 target

Run using the mvn spring-boot:run command

If you run for a long time, please use nohup mvn spring-boot:run

(2) method 2: if the Jar file is already available

Cd to the target directory of the home directory of the project you need to run, the directory of the jar file

[root@xxx target] # lltotal 56372drwxr-xr-x 6 root root 92 May 27 14:23 classesdrwxr-xr-x 2 root root 28 Jun 27 15:06 maven-archiverdrwxr-xr-x 3 root root 35 May 27 14:23 maven-status-rw-r--r-- 1 root root 42572685 Jun 27 15:07 placard_demo-0.0.1-SNAPSHOT.jar-rw-r--r-- 1 root root 15147851 Jun 27 15:07 placard_demo-0.0 .1-SNAPSHOT.jar.originaldrwxr-xr-x 3 root root 17 May 27 14:24 test-classes

Run using the java-jar xxx.jar command

If you are running for a long time, use nohup java-jar xxx.jar

2.3 points for consideration

Using the nohup runtime produces a log file, nohup.out, that contains all console log inputs for the project runtime, so error messages can be viewed against it.

2.4 FAQ

(1) jar file cannot be run

The file permissions of Linux are readable, writable and executable, expressed by r, w and x, respectively.

So unable to run may be a permission problem. Use the ll or ls-a command to view the permissions of the jar file.

Change permissions:

Chmod 777 xx.jar or chmod ugo+x xx.jar

Of course, this is not a very safe behavior, because all users are given full permissions on the file, the relatively safe practice is to use chmod under Baidu.

(2) View the background process

Ps-ef | grep java

If there is a process in the background, you can use the client to test!

The above is how to make your Spring Boot project run on the Linux server. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report