shell run java program to achieve rapid development and deployment

I. Overview

  In the actual development, we write code, often labeled as war package or jar package, by winscp or other software to upload it to the server, but this is very much a drawback that is not conducive to the development, why do you say? If we just will springboot project of the jar package through winscp deployed in linux system, but a variety of sudden, unexpected bug after another, you are in a local test debugging bug, do not you want to play again and again to jar package, upload it to server? I think you'll crazy, ha ha, get down to business.

  Nature run java project is to make jvm run .class file (purely personal understanding, meaning you know like), so why do not we try a local classes directory server directly associated with it, so we uploaded directly modify the debugging .class files can be, and IDEA powerful tool can help us associate classes and local classes file server mapping, which is more convenient for us to develop. Here you can refer to: IDEA WEB automatic deployment project to a remote server (study notes) corresponding directory of the local association mapping server classes.

Second, the test preparation

  ① use IDEA to classes directory of the local and remote server to do the class association mapping ( IDEA WEB automatic deployment project to a remote server (study notes) )

  ② writing shell scripts to run java program

Third, formal testing

  Server-side planning to do the following:

  

  The client only needs to configure directory IDEA association mapping to :( IDEA automatically deploy WEB project to a remote server (study notes) ) Of course, you can also manually local classes, lib dependencies

① prepare the corresponding directory

  

 

 ② ready SpringBoot project

 

 ③ local classes directory and directory servers do association mapping

The first step: To configure the

  

 

 Step two:

  

 

 third step:

  

 

 the fourth step:

  

 

 The final step: the entire directory classes uploaded to the server

  

 

 ④ upload project relies lib to the corresponding file

Write ⑤ shell script to start the program

#!/bin/bash
#测试程序 运行脚本

#jdk路径
JAVA_HOME="/home/software/jdk1.8"

#项目的根目录
APP_HOME="/home/app/test"

#pid的输出目录
PIDFILE="${APP_HOME}/Application.pid"

#指定class目录
CLASSPATH=$APP_HOME/bin

for i in $APP_HOME/lib/*.jar;do
        CLASSPATH="$CLASSPATH":"$i"
done

echo ${CLASSPATH}
MAINCLASS="com.test.demo.DemoApplication"

#后台运行程序
#nohup $JAVA_HOME/bin/java -classpath $CLASSPATH  $MAINCLASS&

#运行java程序
$JAVA_HOME/bin/java -classpath $CLASSPATH  $MAINCLASS

#将进程id写入文件
ps -ef | grep "Application" |grep -v grep|awk '{print $2}'>${PIDFILE}
View Code

⑥通过shell脚本启动该程序:sh start.sh

 

⑦通过浏览器访问:192.168.229.128:8080/test?name=张三(这里确保服务器的8080端口开放) 

 

当我们添加某个类或者修改某个些配置文件的时候,无需进行重新打包、上传服务器等这么麻烦的步骤了,我们只需将添加的class通过IDEA上传即可完成快速部署!

例如:我们新增一个类:TestController,只需要将对应的class提交至服务器即可完成部署!

 

 将对应class提交至服务器!

 至此,我们通过shell脚本运行java程序已经完成!

Guess you like

Origin www.cnblogs.com/rmxd/p/11431621.html