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

Springboot将配置文件打包在jar包外部

程序员文章站 2022-05-02 09:39:18
...
<build>
		<resources>
			<!--指定src/main/resources静态资源要过滤-->
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
		</resources>
		<plugins>
			<!-- 可执行jar插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<outputDirectory>${project.build.directory}/etc</outputDirectory>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<!-- 项目的启动类全限定名(带注解@SpringBootApplication的类) -->
							<mainClass>com.xxx.web.WebServiceApplication</mainClass>
						</manifest>
						<manifestEntries>
							<Class-Path>.</Class-Path>
						</manifestEntries>
					</archive>
					<excludes>
						<exclude>**/*.yml</exclude>
						<exclude>**/*.properties</exclude>
					</excludes>

				</configuration>
			</plugin>
			<!-- maven资源文件复制插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.7</version>
				<!-- 不拦截静态资源(字体.图标) -->
				<!-- <configuration>
					<nonFilteredFileExtensions>
						<nonFilteredFileExtension>xlsx</nonFilteredFileExtension>
						<nonFilteredFileExtension>xls</nonFilteredFileExtension>
						<nonFilteredFileExtension>zip</nonFilteredFileExtension>
						<nonFilteredFileExtension>eot</nonFilteredFileExtension>
						<nonFilteredFileExtension>svg</nonFilteredFileExtension>
						<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
						<nonFilteredFileExtension>woff</nonFilteredFileExtension>
						<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
						<nonFilteredFileExtension>css</nonFilteredFileExtension>
						<nonFilteredFileExtension>js</nonFilteredFileExtension>
						<nonFilteredFileExtension>json</nonFilteredFileExtension>
					</nonFilteredFileExtensions>
				</configuration> -->
				<dependencies>
					<dependency>
						<groupId>org.apache.maven.shared</groupId>
						<artifactId>maven-filtering</artifactId>
						<version>1.3</version>
					</dependency>
				</dependencies>
				<executions>
					<execution>
						<id>copy-resources</id>
						<!-- here the phase you need -->
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.directory}/etc</outputDirectory>
							<resources>
								<resource>
									<directory>src/main/resources</directory>
									<includes>
										<exclude>**/*.yml</exclude>
										<exclude>**/*.properties</exclude>
									</includes>
									<filtering>true</filtering>
								</resource>
							</resources>
							<encoding>UTF-8</encoding>
						</configuration>
					</execution>
				</executions>
			</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>
							<outputDirectory>${project.build.directory}/etc/lib</outputDirectory>
							<!-- 是否不包含间接依赖 -->
							<excludeTransitive>false</excludeTransitive>
							<!-- 忽略版本 -->
							<stripVersion>false</stripVersion>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.18.1</version>
				<configuration>
					<skipTests>true</skipTests>
				</configuration>
			</plugin>
		</plugins>
	</build>

 

相关标签: java