The main point of this article is
- How to introduce step by step SpringBoot The project is deployed to a remote server .
Deploy the whole process
This article uses the creation of Executable jar Way to start SpringBoot project .
1、 To configure maven plug-in unit
<packaging>jar</packaging> <!-- become involved jar package --> <build> <!-- become involved jar The name of the package --> <finalName>fireworks</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.5.RELEASE</version> </plugin> <plugin> <!-- Eliminate the interference of test class on package --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> </plugins> </build>
2、mvn package or mvn install
mvn package and mvn install The difference between ：
- package The code will be compiled , And pack , Finally according to maven Stipulated packaging Way to pack , Finally output to the target directory .
- install It also compiles , And pack , But then install The package will be installed in the local warehouse , For other projects .
# perform mvn clean, Remove previous target Catalog mvn clean # Switch to project path , perform mvn package Instructions mvn package # Output log [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ fireworks --- [INFO] Building jar: D:\Java_Project\firework2.0\target\fireworks.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.3.5.RELEASE:repackage (repackage) @ fireworks --- [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS
Final jar Package output to
D:\Java_Project\firework2.0\target\ Under the table of contents . Enter this directory , You will find that there are two files ：
fireworks.jarIt's what we call executable jar, contain Compiled classes and all that is needed to run jar rely on , If you want to see what's inside , You can use the following command ：
$ jar tvf target/fireworks.jar
fireworks.jar.originalMuch smaller than the former , This is a Maven stay Spring Boot Repackage the original created before jar file , By the command above , You can see that there are no dependencies needed to run , It only contains the compiled .class file .
therefore , If we want to start SpringBoot project , Need to use executable jar, Because it has all the jar rely on , The start command is as follows ：
$ java -jar fireworks.jar
3、 take jar The package is uploaded to the remote server
Use here winSCP, Whatever tool you use , As long as the file can be uploaded to the remote server .
4、 Execute on a remote server jar package
nohup java -jar fireworks-0.0.1-SNAPSHOT.jar & # Background start jar
notes ： If you've started a project before , Remember to shut down the original process ：
ps -ef|grep java kill -9 pid