Linux学习记录

人生就像是漂泊在海上的船,先规划好航线随时准备扬帆启航


一、Linux部署Java项目

1.查看虚拟机正在运行的Java程序

想要查看java程序有没有运行,先查询有没有相关的Java进程。

查看Java进程

ps -ef |grep java

[root@localhost system]# ps -ef |grep java
root       2628      1 99 13:38 pts/0    00:00:17 
/usr/local/src/jdk1.8.0_291/bin/java -server -Xms512m -Xmx512m -XX:+UseG1GC -jar 
-Dloader.path=./lib 
/app/server/system/system-server.jar
root       2656   2596  0 13:38 pts/0    00:00:00 grep --color=auto java

此时有一个进程号为2628的Java程序(system-server)正在运行

补充:

查看指定java进程

ps -ef |grep system-server.jar

查看所有进程命令

ps -ef

2.结束进程

如果要更新正在运行的JAVA程序需要先关闭其进程。

关闭进程命令

kill -9 2628

[root@localhost system]# kill -9 2628
[root@localhost system]# ps -ef |grep system-server.jar
root       2719   2596  0 14:07 pts/0    00:00:00 grep --color=auto system-server.jar

3.上传jar包

上传命令

rz

[root@localhost system]# rz    

会弹出一个上传窗口。

Linux学习记录_第1张图片

[root@localhost system]# ls
demo-0.0.1-SNAPSHOT.jar   system-server.jar

可以看到成功上传到Linux。(也可以使用Xftp上传文件)

补充:若rz命令无效,需要下载

运行如下命令安装rz

yum install lrzsz -y

4.启动项目

运行jar命令

java -jar demo-0.0.1-SNAPSHOT.jar

[root@localhost system]# java -jar demo-0.0.1-SNAPSHOT.jar 

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

2021-06-02 14:37:14.259  INFO 2730 --- [           main] com.demo.DemoApplication                 : Starting DemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_292 on localhost.localdomain with PID 2730 (/app/server/system/demo-0.0.1-SNAPSHOT.jar started by root in /app/server/system)
2021-06-02 14:37:14.261  INFO 2730 --- [           main] com.demo.DemoApplication                 : No active profile set, falling back to default profiles: default
2021-06-02 14:37:15.186  INFO 2730 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-06-02 14:37:15.196  INFO 2730 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-06-02 14:37:15.196  INFO 2730 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-06-02 14:37:15.235  INFO 2730 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-06-02 14:37:15.235  INFO 2730 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 936 ms
2021-06-02 14:37:15.681  INFO 2730 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-06-02 14:37:15.823  WARN 2730 --- [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2021-06-02 14:37:15.911  INFO 2730 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-06-02 14:37:15.924  INFO 2730 --- [           main] com.demo.DemoApplication                 : Started DemoApplication in 2.045 seconds (JVM running for 2.374)

再次查看Java进程

[root@localhost system]# ps -aux|grep demo-0.0.1-SNAPSHOT.jar 
root       2879  0.0  0.0 112824  1000 pts/0    S+   14:54   0:00 grep --color=auto demo-0.0.1-SNAPSHOT.jar

补充:
运行jar命令后可以通过 Ctrl+C 组合键退出


总结

以上就是今天要总结的内容啦,本文仅仅简单介绍了如何把一个Java项目通过jar包的形式发布到Linux。

你可能感兴趣的:(java,linux)