欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot 打jar包时分离配置文件

程序员文章站 2022-05-02 09:54:07
...

修改pom.xml文件

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <!--打包时排除掉资源文件-->
                <excludes>
                    <exclude>**/**</exclude>
                </excludes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <!--打包时去除第三方依赖-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>non-exists</groupId>
                            <artifactId>non-exists</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <!--拷贝第三方依赖文件到指定目录-->
            <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>
                            <!--target/lib是依赖jar包的输出目录,根据自己喜好配置-->
                            <outputDirectory>target/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
  • 在target中把lib目录和jar文件再加了项目中的resource目录一起发布,启动命令是: java -jar -Dloader.path=.,resources,lib (可执行的jar包名称).jar
  • win10 用cmd 不要用powershell