Maven打包SpringBoot项目,排除第三方依赖包

tech2024-03-19  65

项目启动直接

#启动jar包的时候默认会外挂同级lib文件夹下的jar包,如果同层有配置文件也会默认加载 nohup java -jar test.jar &

maven配置直接上xml 原文链接: Maven打包SpringBoot项目,排除第三方依赖包.

<plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <!-- 跳过单元测试 --> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <!-- 复制第三方 jar 到项目目录下的 target/lib/ 下 --> <execution> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeScope>provided</excludeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <!-- 指定 Spring Boot 启动类,实际测试中必须 --> <mainClass>${project.main.class}</mainClass> <!-- 将所有第三方 jar 添加到项目 jar 的 MANIFEST.MF 文件中,这样运行 jar 时依赖包才能被加载 --> <addClasspath>true</addClasspath> <!-- 指定复制第三方 jar 的目标目录为 target/lib/--> <classpathPrefix>./lib/</classpathPrefix> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- repackage 时排除掉 第三方依赖 jar 文件,我们的可运行 Spring Boot 的 jar 文件瞬间变小 ^_^ --> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> </plugin> </plugins>
最新回复(0)