The springboot project packages third-party jars and configuration files outside the jar package

Time:2021-9-21

The springboot project is made into a jar package by default. It is not friendly in multiple environments. It is necessary to package the dependent third-party jar and the configuration files under the resources directory into a directory at the same level as the jar package to facilitate environment change. The specific operations are as follows:

Package to external directory

  1. Pom.xml needs to be modified

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptors>
                        <descriptor>src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                    <outputDirectory>${project.build.directory}/gwall/</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    
            <!--  Package it into a jar file, and specify the Lib folder and the resources resource folder -- >
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.xxl.job.admin.XxlJobAdminApplication</mainClass>
                            <!-- Dependent prefix -- >
                            <classpathPrefix>lib/</classpathPrefix>
                            <addClasspath>true</addClasspath>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>resources/</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
  2. Add profile
    The springboot project packages third-party jars and configuration files outside the jar package
    The contents of the assembly.xml file are as follows:

    <assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    
    <id>distribution</id>
    
    <!-- Output format zip final result generated zip -- >
    <formats>
        <format>tar.gz</format>
    </formats>
    
    <includeBaseDirectory>false</includeBaseDirectory>
    
    <!-- Set required output file -- >
    <fileSets>
        <fileSet>
            <directory>src/main/bin</directory>
            <outputDirectory>/</outputDirectory>
            <fileMode>0755</fileMode>
        </fileSet>
        <fileSet>
            <directory>src/main/resources/</directory>
            <outputDirectory>/resources</outputDirectory>
            <fileMode>0644</fileMode>
        </fileSet>
    </fileSets>
    
    <dependencySets>
        <dependencySet>
            <!-- Dependent package output directory -- >
            <outputDirectory>/lib</outputDirectory>
            <scope>runtime</scope>
            <excludes>
                <exclude>${project.groupId}:${project.artifactId}</exclude>
            </excludes>
        </dependencySet>
        <dependencySet>
            <!-- Output directory of jar package -- >
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>${project.groupId}:${project.artifactId}</include>
            </includes>
        </dependencySet>
    </dependencySets></assembly>

    The contents of the start.sh file are as follows:

    #!/bin/bash
    curpath=`pwd`
    app=xxl-job-admin-2.1.0.jar
    echo 'curpath:$curpath    app:$app'
    ps -aux|grep $curpath/$app|grep -v grep|awk '{print $2}'|xargs -r kill -9
    nohup java  -jar $curpath/$app > $curpath/nohup.out 2>&1 &

    The contents of the start.bat file are as follows:

    @echo off & setlocal enabledelayedexpansion
    java -jar xxl-job-admin-2.1.0.jar
    pause

    The final results are as follows:

    The springboot project packages third-party jars and configuration files outside the jar package
    The springboot project packages third-party jars and configuration files outside the jar package
    The springboot project packages third-party jars and configuration files outside the jar package

    Attention problem

    Logback does not take effect

    It mainly uses logback-spring.xml
    In addition, it needs to be configured in application.yml

     logging:
       config: config/logback-spring.xml

    See:
    https://my.oschina.net/u/2022…

Recommended Today

I want to discuss canvas 2D and webgl with you

background This article is included inData visualization and graphicsspecial column As mentioned above, I wrote my first column and realized a simple program for the cognition of graphics and visualization. It was originally intended that the follow-up sequence has focused on the algorithm and rendering direction. However, based on the students’ feedback on obscure problems […]