Packing configuration SpringBoot third party dependencies removed

Currently set up springboot micro Services Architecture is the most popular. Very convenient to use. Build springboot architecture. Please refer to other documents on their own. This section is the main problem. Our package upload deployment.

 

Before we pack, it is the entire project labeled jar or war in the form of packets. Uploads are hundreds of mb size, then the next we how. Slimming package. And deploy it?

 1. to understand the principle:

    Packaging and weight-loss difference between normal packaging. On the point: (1) BOOT-INF / lib rely on third parties or absence of packets.

Dry goods directly Code:

WIN10 system:

1. Normal packing

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!-- 指定该Main Class为全局的唯一入口 -->
                <mainClass>com.cy.plat.cyadmin.CyAdminApplication</mainClass>
                <layout>ZIP</layout>
                <includes>
                    <!-- 设置没有jar包-->
                    <!--<include>
                        <groupId>nothing</groupId>
                        <artifactId>nothing</artifactId>
                    </include>-->
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal><!- </->can be dependent packages are packed into the resulting package Jar
                    goals>
                </execution>
            </executions>
        </plugin>
        <!--<plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.3</version>
            <configuration>
                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                <dockerDirectory>src/main/docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>-->
    </plugins>
</build>

2. slimming package:

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!-- 指定该Main Class为全局的唯一入口 -->
                <mainClass>com.cy.plat.cyadmin.CyAdminApplication</mainClass>
                <layout>ZIP</layout>
                <includes>
                    <!-- 设置没有jar包-->
                    <include>
                        <groupId>nothing</groupId>
                        <artifactId>nothing</artifactId>
                    </include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!--<plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.3</version>
            <configuration>
                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                <dockerDirectory>src/main/docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>-->
    </plugins>
</build>

Comparison method is actually

That is spring-boot-maven-plugin this plugin, add this sentence

<!-- 设置没有jar包-->
            <include>
                   <groupId>nothing</groupId>
                   <artifactId>nothing</artifactId>
               </include>                    

 

3. How to deploy:

We normally packed extract out the project. Find BOOT-INF / lib lib the whole package, copy, into the jar and thin package put in the same directory:

 

 

Last start command:

java -Dloader.path=/path/to/lib -jar /path/to/cy-admin.jar

Remarks:

  • The / path / to / into the actual path.
  • -Dloader.path = lib folder path

Or the current directory can use this command:

java -Dloader.path=./lib -jar ./cy-admin.jar

 

Then started finished .

Guess you like

Origin www.cnblogs.com/zouhong/p/12189476.html