Realize the packaging and publishing of java project idea to the server (full version)

Question: How to quickly deploy local code to the server?

What I will introduce today is to use a plug-in (Alibaba Cloud Toolkit) of idea to implement it. First, you need to install the operating environment on your own server, including: jdk, maven, mysql, etc. These operations will not be described in detail, but Baidu can solve them.

1. First, you can download the plug-in in the plug-in market, and restart idea after installation to make it take effect.

2. After the installation is complete, configure it, right-click Host, and add your own server.

After clicking, fill in your own server ip, user name, password, and then test the link, if it shows succeeded, it means the connection is successful!

Below is my server configuration, using Alibaba Cloud server.

 

 3. After the creation is complete, you can see your own server below

 4. Prepare a Java project, right click on the project to add configuration

5. First click the plus sign to select the server configuration you just added, and then click below

Target Directory packages your java project into a jar and sends it to the target address of the server, such as /root/test path

After deploy is the address of the script file, and the content of the script is to start the program, record logs and other operations, and a script template is provided below

6. You can set the log output here:

 7. After clicking Finish, you can choose to run it here. After running, the project will be packaged and tested first!

 Script template:

File name: demo.sh, the content is as follows

To put it simply, jarName is the name of the jar package, demo.log is the file that stores the running log, and the middle part is to judge whether the program is running. If it is running, stop it first and then start it.

The first line of path is the running environment configuration file on the server, such as jdk\maven

source /etc/profile
# jar的名称
jarName=wheel-back.jar
PID=`ps -ef|grep $jarName |grep -v grep|awk '{print $2}' `
if [ -n "$PID" ]; then
    kill -9 $PID
    echo "结束$PID进程"
fi
nohup java -jar  /lqy/jar/$jarName > demo.log 2>&1 &
echo $jarName"服务部署完毕!"

Notice:

Possible problems, edit the file locally and put it on the server, and report an error after running:

 /etc/profile : No such file or directory

Solution: The .sh file suffix script format edited locally with notepad++ is incorrect, and the file format needs to be changed

The operation on the server is as follows:

vi demo.log
:set ff

You can see that the file is in dos format

enter:

:set ff=unix

 Then save it and it's ok! ! !

Finally, I recommend a client that operates a linux server locally, Termius, which supports mac and win at the same time. It feels more useful. Of course, if you are win, you can also use xshell, because you usually use mac at work and win at home, so this is more recommended ! ! ! !

Official website address: Termius official website

Welcome to exchange other useful clients in the comment area! ! !

Guess you like

Origin blog.csdn.net/qq_37764320/article/details/128161286