springboot 打jar包時分離配置文件


修改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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM