乐趣区

关于java:49springboot-打jar独立出三方的依赖包

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <!-- 指定该 jar 包启动时的主类[倡议] -->
                    <mainClass>com.linewell.AppApplication</mainClass>
                    <layout>ZIP</layout>
                    <includes>
                        <!-- 排除第三方依赖 jar(只保留本我的项目的 jar) -->
                        <include>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>

            <!-- 把我的项目依赖的第三方包打包在 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>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <resources>

            <!-- 排除 resources 下的配置文件 -->
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>static/**</exclude>
                    <exclude>templates/**</exclude>
                    <exclude>*.yml</exclude>
                    <exclude>*.properties</exclude>
                    <exclude>*.xml</exclude>
                    <exclude>*.txt</exclude>
                    <exclude>*.json</exclude>
                    <exclude>codetemplate/**</exclude>
                    <exclude>lib/**</exclude>
                </excludes>
                <targetPath>BOOT-INF/classes/</targetPath>
            </resource>

            <!-- 打包 lib 下的 jar 包 -->
            <resource>
                <directory>lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>


        </resources>
        <finalName>sqjw</finalName>
    </build>

新建一个独立目录,将 targer/lib、sqjw.jar 拷过来。
将 src/main/resources/ 底下的配置文件 (即 resource 排除的) 也拷过来。
运行:

java -jar -Dloader.path=lib sqjw.jar

之后程序更新,只须要更新 sqjw.jar,其余不变。

退出移动版