[Maven] springboot the specified directory to the jar packetizing

Hello everyone, I am a duck:
Share today at springboot the jar package package to the specified directory.
Because the lines are before a packed into a jar, due to the multi-service, and a pack of more than 100 M, even if it is a small version of the line will need to re-upload the jar package.

1. Purpose


Will not be used such as spring, druid not commonly used to package lib directory, so that each of these on-line does not need to upload. Third party or changes often also packaged into the jar package itself, every time a new line will be packaged.
Such original M jar package 100, may become 2,3M.
As shown:
the original are packaged

Change the mode after:

2. Modify pom


Briefly, the label is inside includes a third-party package into the jar jar. After the package above 2M solution compression package that includes. as the picture shows.

excludeGroupIds and excludeArtifactIds is not configured lib directory of the package, due to the mechanism of java to load the boot loader is a priority jar package,
and then load an external directory, if the jar package there are two places, so that the configuration does not make sense, each still have to re published lib directory, it will be includes
in the package, and then in excludeGroupIds and excludeArtifactIds configuration
.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.5.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <layout>ZIP</layout>
                <includes>
                    <include>
                        <groupId>nothing</groupId>
                        <artifactId>nothing</artifactId>
                    </include>
                    <include>
                        <groupId>com.etc</groupId>
                        <artifactId>etc-manage-api</artifactId>
                    </include>
                    <include>
                        <groupId>com.etc</groupId>
                        <artifactId>etc-manage-core</artifactId>
                    </include>
                    <include>
                        <groupId>com.etc</groupId>
                        <artifactId>etc-manage-rpc-api</artifactId>
                    </include>
                    <include>
                        <groupId>com.sinoiov.etc.apollo</groupId>
                        <artifactId>apollo-spring-boot-starter</artifactId>
                    </include>
                </includes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <excludeGroupIds>
                            com.sinoiov.etc.apollo
                        </excludeGroupIds>
                        <excludeArtifactIds>
                            etc-manage-api,etc-manage-core,etc-manage-rpc-api
                        </excludeArtifactIds>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

3. Modify the startup script


Original screenplay

java -jar etc-manage-service-basic-2.2.0.jar

Now the script (if relatively difficult to use directory, try to use absolute directory)

java Dloader.path=../lib  -jar etc-manage-service-basic-2.2.0.jar

 

Published 115 original articles · won praise 58 · Views 230,000 +

Guess you like

Origin blog.csdn.net/Angry_Mills/article/details/105024664