Spring boot packaging and deployment problem solving

Based on Maven to package and deploy spring boot projects, most of them on the Internet are:

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
                <mainClass>${start-class}</mainClass>
            </configuration>
              <executions>
                <execution>
                  <goals>
                    <goal>repackage</goal>
                  </goals>
                </execution>
            </executions>
        </plugin>

The problem is that the whole project is a jar after packaging, and other jars it depends on will also be included, which makes the whole project very large. Every time the project is updated, the entire jar package must be updated, which is very troublesome.

Is there a way to separate the jars that the project depends on? When deploying an updated project, you only need to update the code of the project itself, without updating the dependent packages.

The directory structure after the project jar package is decompressed:

 

The solution is to use the following configuration in the pom instead:

<plugin>
		   <groupId>org.springframework.boot</groupId>
		   <artifactId>spring-boot-maven-plugin</artifactId>
		   <configuration>
		      <layout>ZIP</layout>
		      <minimizeJar>true</minimizeJar>
		   </configuration>
		</plugin>

 The project tboot.jar obtained after packaging, copy the lib, and then delete the lib and the dependent packages in the directory directly from the jar

 

In this way, we get our business code, deploy it to the Linux server, and store the lib dependency package separately:

 

Command to start the project: java  -Dloader.path="lib/"  -jar tboot.jar

Project is running normally

In addition, the background startup method is attached, and the shell script startup.sh has been written (the script file is placed in the same directory as the project tboot.jar):

#!/bin/sh
#Function introduction: start the jar file in the upper directory
#Parameter introduction:
# $1:jar file name (including suffix name)
# Note: The jar file must be located one level above the startup.sh directory.

#startup parameters
JAVA_OPTS="-server -Xms400m -Xmx400m -Xmn300m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xverify:none -XX:+DisableExplicitGC -Djava.awt.headless=true"

jar_name=$1
this_dir="$( cd "$( dirname "$0"  )" && pwd )"
parent_dir=`dirname "${this_dir}"`
log_dir="${parent_dir}/logs"
log_file="${log_dir}/catalina.out"
jar_file="${jar_name}"
#Dependency package directory (relative path)
lib_dir="lib/"

#When the number of parameters is less than 1 or the parameter is empty, the execution will be interrupted
if [ $# -lt 1 ] || [ -z $1 ]; then
    echo -e "\033[31mPlease enter the name of the jar package to be deployed!\033[0m"
    exit 1
be

#log folder does not exist, then create
if [ ! -d "${log_dir}" ]; then
    mkdir "${log_dir}"
be

#The jar file exists in the parent directory
if [ -f "${jar_file}" ]; then
    #Start the jar package; redirect standard error output to a file, discard standard output
    java $JAVA_OPTS -Dloader.path=${lib_dir} -jar ${jar_file} 1>/dev/null 2>"${log_file}" &
    exit 0
else
    echo -e "\033[31m${jar_file} file does not exist!\033[0m"
    exit 1
be

 

Supplement: Maven hits the plugin configuration of the executable Jar package (based on Dubbo)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326181230&siteId=291194637