SpringBoot打包分離依賴jar和資源文件

參考資料 maven-dependency-plugin 嘗試了網上的不少配置,在我本機試了都有不少問題,要麼依賴jar沒有拷貝出來 要麼就是eclipse報警告,嘗試不少次最終解決了html

mvn -package 打包後拷貝target下的 jar文件和 resources 及 libjava

執行方式:java -jar a.jarapache

配置以下:eclipse

<build>
		<finalName>sample</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArguments>
						<verbose />
						<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
					</compilerArguments>
				</configuration>
			</plugin>
			<!--**********分離資源文件及依賴包打包配置************* -->
			<!--打包jar -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<!--不打包資源文件 -->
					<excludes>
						<exclude>*.**</exclude>
						<exclude>static/**</exclude>
						<exclude>templates/**</exclude>
						<exclude>config/**</exclude>
					</excludes>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<!--MANIFEST.MF 中 Class-Path 加入前綴 -->
							<classpathPrefix>lib/</classpathPrefix>
							<!--jar包不包含惟一版本標識 -->
							<useUniqueVersions>false</useUniqueVersions>
							<!--指定入口類 -->
							<mainClass>com.beone.AppAdminApplication</mainClass>
						</manifest>
						<manifestEntries>
							<!--MANIFEST.MF 中 Class-Path 加入資源文件目錄 -->
							<Class-Path>./resources/</Class-Path>
						</manifestEntries>
					</archive>
					<outputDirectory>${project.build.directory}</outputDirectory>
				</configuration>
			</plugin>

			<!--拷貝資源文件 copy-resources -->
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>copy-resources</id>
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<resources>
								<resource>
									<directory>src/main/resources</directory>
								</resource>
							</resources>
							<outputDirectory>${project.build.directory}/resources</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- 先在pluginManagement中聲明再使用 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
			</plugin>
		</plugins>
		<pluginManagement>
			<plugins>
				<!--拷貝依賴 copy-dependencies -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-dependency-plugin</artifactId>
					<executions>
						<execution>
							<phase>package</phase>
							<goals>
								<goal>copy-dependencies</goal>
							</goals>
						</execution>
					</executions>
					<configuration>
						<includeScope>compile</includeScope>
						<outputDirectory>${project.build.directory}/lib</outputDirectory>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>

可作參考的其餘資料1maven

相關文章
相關標籤/搜索