ready
- SpringBoot project
Among them, the use of Maven project management tools
- Linux
My Linux distribution is CentOS 7, which is an Alibaba Cloud server
student "online practice" plan . Students can receive a 6-month server for free-in fact, students are not expensive to buy a server, it is recommended to get a play
- Remote connection to Linux tools
Xftp, Xshell is very easy to use
Linux operation (1) Basic operation-remote login and user management
Package the project
We know that SpringBoot has built-in Tomcat, just need to package it into a jar file and run it on Linux
If you are using Maven to manage the project, you can directly
package it through Maven, click on the right side Maven Projects , double-click the package will automatically package
(Windows can also use the cmd command to package under the Maven folder)
This problem may occur:
Running com.myblog.blog.BlogApplicationTests
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 0.002 sec <<< FAILURE! - in com.myblog.blog.BlogApplicationTests
initializationError(com.myblog.blog.BlogApplicationTests) Time elapsed: 0.001 sec <<< ERROR!
java.lang.Exception: The class com.myblog.blog.BlogApplicationTests is not public.
Cause packaging failure
This is the maven-surefire-plugin component missing in Maven
Add under build-> plugins tag
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
This is the successful packaging
Go to the target folder under your project to find the jar file, such as my address isD:\JavaProject\blog\SpringBootBlog\target\blog-0.0.1-SNAPSHOT.jar
Transfer this jar package to Linux
Linux running
Put the jar package in the directory you want to run
I put it under / opt / blog
You need to install jdk under Linux (need to run jar project)
Note: Whether your database is put into Linux,
after all, SpringBoot will verify the database connection during the running phase
Note: Alibaba Cloud needs to set up a security group.
There is a security group setting on the left side of the console
Click to configure rules
Click to quickly create a rule , you need to change three places:
8080/8080 security group port number (3306 is the port number of the Mysql server)
1 Priority: the lower the priority, the higher the
0.0.0.0/0 authorized object: allow all IP access
ok, the priority is set
Run the jar project:java -jar 项目名
The springboot icon comes out (I changed the springboot icon to NO BUG)
The operation may report errors:
o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.
Port 8080 is occupied
First check the port number:netstat -tunlp |grep 8080
There is a process occupying my port 8080
Can kill this process: kill -9 2814
-9 is forced to kill this process, 2814 is the process number that occupies my port
8080 is free after killing
Run
ok again , the operation is successful, access the project through the public IP (if it is not accessible, it may be a firewall problem iptables, firewall)
Because it is a command line interface, our interface is the SpringBoot console
ctrl + c to exit, return
But the problem is that when we quit, SpringBoot quits,
and the effect we want is that the cloud server continues to run the server in the background
Continuously running in the background
Can write a shell step to complete
Create one in the current directorystartup.sh
vim startup.sh
The command is two lines. The first line is not a comment when it runs. It means that this script uses / bin / sh to explain the execution. The interpreter explains
the address of the second line to write its own jar file. -0.0.1-SNAPSHOT.jar
#!/bin/sh
nohup java -jar /opt/blog/blog-0.0.1-SNAPSHOT.jar &
After the script is written, there is no running permission at the beginning, and there are setting permissions chmod +x startup.sh
to give executable permissions
Running shell script./startup.sh
Run in the background, the console information will be placed in nohup.out
You can also use the project in SpringBoot by closing Xshell
Conclusion
The project will eventually be deployed to Linux.
Also, welcome to visit my personal blog