快捷搜索: 王者荣耀 脱发

Springboot项目部署到服务器

在项目中涉及到了项目部署到服务器,不想让你的代码只在本机可以看见的话可以参考本篇博客。

一下是我的详解

首先打开idea 直接mvn clean,然后mvn install

这时候在你的target下就生成了jar包,请看目录

拿到了jar包就好说了,在本地跑一下先(windows)

在对应路径 输入cmd 好戏开始

D:IdeaProjectsdemo	arget>java -jar bayimade-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\ / ____ __ _ _(_)_ __  __ _    
( ( )\___ | _ | _| | _ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
    |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.3.RELEASE)

2021-12-02 10:52:21.574  INFO 3652 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on ISS460602008203 with PID 3652 (D:IdeaProjectsdemo	argetayimade-0.0.1-SNAPSHOT.jar started by gxhuh in D:IdeaProjectsdemo	arget)
2021-12-02 10:52:21.576  INFO 3652 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-12-02 10:52:22.999  INFO 3652 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8093 (http)
2021-12-02 10:52:23.011  INFO 3652 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-12-02 10:52:23.011  INFO 3652 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2021-12-02 10:52:23.093  INFO 3652 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-12-02 10:52:23.094  INFO 3652 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1462 ms
Loading class `com.mysql.jdbc.Driver. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-12-02 10:52:23.557  INFO 3652 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService applicationTaskExecutor
2021-12-02 10:52:23.663  INFO 3652 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
2021-12-02 10:52:23.875  INFO 3652 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8093 (http) with context path 
2021-12-02 10:52:23.889  INFO 3652 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 2.728 seconds (JVM running for 3.272)

服务跑起来了输入 localhost:8001/ 看看能启动不到这里第一步你已经搞定了,本地服务部署OK

那么怎么部署到服务器呢?

不要慌大朗吃口药且看我娓娓道来

这里采用linux上的服务器,繁琐的部署太麻烦直接请出我们的xshell,xftp或者看我的博客stfp怎么上传文件 把你刚才的jar包传到服务器就行,通过xftp也可以上传的

传上去后 执行以下代码

[root@instance-00p98pt3 ~]# cd hubayi
[root@instance-00p98pt3 hubayi]# ls
a.txt  bayimade-0.0.1-SNAPSHOT.jar  b.txt  nohup.out
[root@instance-00p98pt3 hubayi]# nohup java -jar baiyimade.jar

nohup java - jar jar表示在linux端一直执行 这个jar包 但是还有一个问题这里你需要把你的数据库也部署上去

数据库怎么部署更简单的直接用navcat 链接数据库

进去后把你本地的数据库导出,在导入进去就行了

注意 要先部署你的数据库然后在运行 nohup java -jar jar包

部署好了后 直接 ip:8080/ 访问即可 比如说 服务器ip 10.100.10.111

10.100.10.111:8080/ 在本机访问成功 即表示部署成功了

经验分享 程序员 微信小程序 职场和发展