Complete steps for deploying jar package projects using Shell scripts in Linux

Complete steps for deploying jar package projects using Shell scripts in Linux

1. Install JDK

Check the computer's operating digits:
uname -ar

2017 x86_64 x86_64 x86_64 GNU/Linux
If it is shown here as 64-bit, download the corresponding 64-bit package

Download address of jdk, it is recommended to download the tar.gz package
www.oracle.com/technetwork…

Now start the official installation of JDK

1. Upload the jdk installation package to /root

jdk-8u131-linux-x64.tar.gz

2. Confirm whether the system has already installed JDK

rpm -qa|grep jdk
rpm -e --nodeps software name //If it is checked that it is installed, execute the uninstall command

3. Unzip the jdk installation package to the specified directory

tar -xvf jdk-8u131-linux-x64.tar.gz -C /usr/local/

4. Enter the decompression directory

cd /usr/local

5. Modify the jdk folder name

mv jdk1.8.0_131 jdk

6. Configure environment variables

Modify the environment variable configuration file:

vi /etc/profile

Press i to enter edit mode

Jump to the last line and add the following content. Please note that the JDK here should be consistent with the path where you installed JDK.

#java runtime setting
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=$JAVA_HOME/lib:.
export PATH=$JAVA_HOME/bin:$PATH

Press ESC and enter :wq to save and exit

7. Reload environment configuration

source /etc/profile

8. Test whether JDK installation is ok

java -version

9. Write hello.java

vi Hello.java

class Hello{
	public static void main(String[] args){
	System.out.println("hello,java");
	}
}

Then press ESC :wq to exit

vi /etc/profile i write

javac Hello.java

2. Deploy jar package

1. Create data, then create a test directory, and create related folders and files according to the following structure

The directory structure is:


Place the main jar package under app, such as myjar, and the following is the content of the related restart.sh:

#!/bin/bash

base_home='/data/test'
app_name='myjar'

pid=`ps -ef|grep ${app_name}|grep -v grep|grep -v restart|awk '{print$2}'`
if [ -n "${pid}" ] ;then
 kill -9 ${pid}
 sleep 10
fi

gclog_file=$base_home/log/gc.log
dump_dir=$base_home/heapdump
errorlogs_dir=$base_home/log

java -Xmx1g -Xms1g -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:GCLogFileSize=128M -XX:NumberOfGCLogFiles=1 -Xloggc:${gclog_file} -XX:HeapDumpPath=${dump_dir} -jar $base_home/app/${app_name}.jar --spring.config.location=$base_home/config/application.yml >> $base_home/log/${app_name}_$(date +'%Y%m%d').log &

It should be noted here that {app_name}.jar may contain the following errors:

Error: Unable to access jarfile /app/myjar.jar

Here you may need to change to an absolute path, as follows:

/datat/test/app/${app_name}.jar

Access the relevant path: (modify here according to the relevant port of your jar

http://ip:8080/

View the log path:

cd /log
Here, the log file with the name and date of the relevant jar package will be displayed, such as: myjar_20190530.log

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Linux shell script to start jar package
  • Shell script for one-click restart of Jar package and some experience sharing of new server deployment
  • How to start jar package with custom shell script in Linux

<<:  A practical record of restoring a MySQL Slave library

>>:  Vue two same-level components to achieve value transfer

Recommend

What codes should I master when learning web page design?

This article introduces in detail some of the tech...

Two methods of restoring MySQL data

1. Introduction Some time ago, there were a serie...

Detailed explanation of Vuex environment

Table of contents Build Vuex environment Summariz...

MySQL 5.7.19 (tar.gz) installation graphic tutorial under Linux

The first tutorial for installing MySQL-5.7.19 ve...

A brief analysis of the usage of HTML float

Some usage of float Left suspension: float:left; ...

Singleton design pattern in JavaScript

Table of contents 1. What is a design pattern? 2....

Text mode in IE! Introduction to the role of DOCTYPE

After solving the form auto-fill problem discussed...

Summary of Vue 3 custom directive development

What is a directive? Both Angular and Vue have th...

How to publish static resources in nginx

step Place the prepared static resource files in ...

MySQL 8.0.15 download and installation detailed tutorial is a must for novices!

This article records the specific steps for downl...

Linux bridge method steps to bridge two VirtualBox virtual networks

This article originated from my complaints about ...

OpenSSL implements two-way authentication tutorial (with server and client code)

1. Background 1.1 Problems A recent product testi...