SpringBoot剔除三方库与配置资源
一、在pom.xml中的build加入以下配置:
<build> <finalName>${project.artifactId}</finalName> <plugins> <!--打包跳过测试类--> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <!--<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <includeSystemScope>true</includeSystemScope> <mainClass>com.irobot.robotdev.RobotDevApplication</mainClass> <includes> <!– 设置没有jar包–> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> </plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <!--MANIFEST.MF 中 Class-Path 加入前缀! 用命令java -jar运行jar时就不用-Dloader.path指定外部资源路径了--> <classpathPrefix>lib/</classpathPrefix> <!--jar包名字是否包含唯一版本标识--> <useUniqueVersions>false</useUniqueVersions> <!--指定含main方法的主类入口--> <mainClass>com.irobot.robotdev.RobotDevApplication</mainClass> </manifest> <manifestEntries> <!--MANIFEST.MF 中 Class-Path 加入资源文件目录! 用命令java -jar时就不用-Dloader.path指定外部资源路径了 --> <Class-Path>resources/</Class-Path> </manifestEntries> </archive> <!-- 打包时从jar包里排除资源文件 --> <excludes> <exclude>*.yml</exclude> <exclude>*.properties</exclude> <exclude>mapper/*.xml</exclude> </excludes> <!-- 指定项目打成jar包输出位置 --> <outputDirectory>${project.build.directory}/</outputDirectory> </configuration> </plugin> <!-- 将三方库jar单独拷贝至lib目录 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-lib</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> </plugins> <!-- 资源配置 --> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <!-- 剔除项目中的配置文件 --> <resource> <directory>src/main/resources</directory> <excludes> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> <exclude>**/*.properties</exclude> <exclude>**/*.sh</exclude> <!--<exclude>**/*.sql</exclude>--> <exclude>**/*.txt</exclude> </excludes> <filtering>true</filtering> </resource> </resources> </build>
二、在服务器三方库、配置文件
三方库存在在lib目录下面,配置资源存放在config目录下。如图所示:
./springboot.sh start test-boot.jar