请教一个maven打包发布时的问题

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<artifactId>jshouse</artifactId>
	<groupId>com.quickplan.common</groupId>
	<version>1.0</version>
	<packaging>jar</packaging>

	<name>jshouse</name>

	<properties>
	</properties>

	<build>
		<!-- <finalName>jshouse</finalName> -->

		<outputDirectory>${project.basedir}/WebRoot/WEB-INF/classes</outputDirectory>
		<plugins>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.6.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<!-- java8 保留参数名编译参数 -->
					<compilerArgument>-parameters</compilerArgument>
					<compilerArguments>
						<verbose />
					</compilerArguments>
				</configuration>
			</plugin>

			<!-- jar 包中的配置文件优先级高于 config 目录下的 "同名文件" 因此,打包时需要排除掉 jar 包中来自 src/main/resources 
				目录的 配置文件,否则部署时 config 目录中的同名配置文件不会生效 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<excludes>
						<exclude>*.txt</exclude>
						<exclude>*.xml</exclude>
						<exclude>*.properties</exclude>
					</excludes>
				</configuration>
			</plugin>

			<!-- 使用 mvn clean package 打包 更多配置可参考官司方文档:http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>

						<configuration>
							<!-- 打包生成的文件名 -->
							<finalName>${project.artifactId}</finalName>
							<!-- jar 等压缩文件在被打包进入 zip、tar.gz 时是否压缩,设置为 false 可加快打包速度 -->
							<recompressZippedFiles>false</recompressZippedFiles>
							<!-- 打包生成的文件是否要追加 release.xml 中定义的 id 值 -->
							<appendAssemblyId>true</appendAssemblyId>
							<!-- 指向打包描述文件 package.xml -->
							<descriptors>
								<descriptor>package.xml</descriptor>
							</descriptors>
							<!-- 打包结果输出的基础目录 -->
							<outputDirectory>target/</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>

	<dependencies>

	</dependencies>
</project>

pom.xml↑

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
	
	<!-- 
		assembly 打包配置更多配置可参考官方文档:
			http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
	 -->
	
	<id>release</id>
	
	<!--
		设置打包格式,可同时设置多种格式,常用格式有:dir、zip、tar、tar.gz
			dir 格式便于在本地测试打包结果
			zip 格式便于 windows 系统下解压运行
			tar、tar.gz 格式便于 linux 系统下解压运行
	 -->
	<formats>
		<format>dir</format>
		<format>zip</format>
		<!-- <format>tar.gz</format> -->
	</formats>
	
	<!-- 打 zip 设置为 true 时,会在 zip 包中生成一个根目录,打 dir 时设置为 false 少层目录 -->
	<includeBaseDirectory>true</includeBaseDirectory>
	
	<fileSets>

		<fileSet>
			<directory>${basedir}/WebRoot</directory>
			<outputDirectory>WebRoot</outputDirectory>
			<excludes>
				<exclude>WEB-INF/classes/config.txt</exclude><!-- 去掉开发用的配置文件 -->
				<exclude>userfiles/**</exclude><!-- 去掉开发环境中的上传文件 -->
			</excludes>
		</fileSet>
		
		<!-- 项目根下面的脚本文件 copy 到根目录下 -->
		<!-- 脚本文件在 linux 下的权限设为 755,无需 chmod 可直接运行 -->
		<fileSet>
			<directory>${basedir}</directory>
			<outputDirectory></outputDirectory>
			<fileMode>755</fileMode>
			<includes>
				<include>*.bat</include>
				<include>*.sh</include>
			</includes>
		</fileSet>
	</fileSets>
	
	<!-- 依赖的 jar 包 copy 到 lib 目录下 -->
	<dependencySets>
		<dependencySet>
			<outputDirectory>WebRoot/WEB-INF/lib</outputDirectory>			
		</dependencySet>
	</dependencySets>
	
</assembly>

package.xml↑


配置内容如上,基本是照抄jfinalmaven的,每次eclipse上运行mvn install之后,除了在项目的target目录生成打包文件以外,电脑本地的maven缓存目录\Maven\repository\里也会出现一个打包后的压缩文件,导致开发项目多了会生成数量容量巨多的release压缩包


试过百度搜索解决方法,但是没有头绪,连准确描述的关键词都没有,搜索很多的帖子讨论的都是不是我所关心的问题

想问一下有没有大佬知道这种现象是哪里出了问题,或者配置不正确

谢谢指教

评论区

zzutligang

2023-03-02 17:15

你别执行mvn install,直接执行mvn package不就行了吗?你让mvn把你的jar安装到本地仓库,它肯定得这么干啊。

zeroabc

2023-03-02 18:17

@zzutligang 刚刚试了,但是这样并没有打包出部署要用的文件夹内容

JFinal

2023-03-02 23:24

@zeroabc 执行 mvn clean package 就可以了,打出的压缩包与可执行的目录在 target 目录下面的以项目名称命令的子目录下面,注意找一下

JFinal

2023-03-02 23:25

严格参考俱乐部给的 pom.xml 与 package.xml 文件,其中 package.xml 文件的内容完全不用动,pom.xml 中的 maven-assembly-plugin 配置不要动它

zeroabc

2023-03-03 14:46

@JFinal mvn clean只会清理项目target里面的所有文件,但是本地maven缓存仓库的打包文件还在,不会清理。如果之前没留意过这个问题,可以去\Maven\repository\看看,找自己项目常用的groupId对应的文件夹,会发现目录极其巨大

chcode

2023-03-04 21:45

@zeroabc 你为啥要把项目安装到本地仓库,建议去补下maven基础知识

zeroabc

2023-03-05 16:53

@chcode 现在就是毫无头绪,不知道是maven本身设计如此还是什么别的原因,否则我也不会来问了。你没有这个问题?有没有看过自己开发环境本地的maven仓库文件夹?

热门反馈

扫码入社