归类 : SpringBoot

使用-Dloader.path=/path/to/lib命令指定依赖包路径,那么BOOT-INF/lib路径下的依赖包就不用打包进项目发行包中。

上配置

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <layout>ZIP</layout>
            <includes>
                <!-- 发行包不包含依赖jar -->
                <include>
                    <groupId>nothing</groupId>
                    <artifactId>nothing</artifactId>
                </include>
            </includes>
            <attach>false</attach>
        </configuration>
    </plugin>
    <!-- 下载依赖jar包进入target/lib -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <type>jar</type>
                <includeTypes>jar</includeTypes>
                <includeScope>runtime</includeScope>
                <outputDirectory>
                ${project.build.directory}/lib
                </outputDirectory>
            </configuration>
            </execution>
        </executions>
    </plugin>

Maven clean install 打包

共包含2个关键部分

maven-dependency-plugin

会更新${project.build.directory}/lib一般是target/lib目录下的依赖jar

spring-boot-maven-plugin

打包,不包含依赖

    <include>
        <groupId>nothing</groupId>
        <artifactId>nothing</artifactId>
    </include>

上传

  • 上传发行包
  • 上传/libtarget/lib目录下的依赖jar到服务器,假设上传至 /home/lib
  • java -Dloader.path=/home/lib -jar (其他参数)

以上