我的文件夹中有一个zip.xml名为assembly:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3
http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>archive</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
</fileSet>
<fileSet>
<directory>src/main/resources/</directory>
<includes>
<include>plugin-descriptor.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
使用 构建项目后mvn clean -U -DskipTests package assembly:assembly,我注意到只有jar文件被复制并压缩到存档中。
如何将properties文件归档到 zip 文件中?所需的 zip 应该在根目录中包含 jar 和属性文件
您应该定义一个<files>元素而不是 a,<fileSets>因为您想要复制特定的单个文件而不是目录。在这种情况下,您想要复制:
${project.build.directory}/${project.build.finalName}.${project.packaging}ZIP 的根目录src/main/resources/plugin-descriptor.properties放入 ZIP 的根目录中您当前的配置是错误的,因为您声明 ZIP 下的所有条目${project.build.directory},这不是您想要的,因为您只对最终的 JAR 感兴趣。另外,用作/基本目录有点奇怪;最好说我们不想要一个带有以下内容的基本目录<includeBaseDirectory>false</includeBaseDirectory>
示例配置如下:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3
http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>archive</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>${basedir}/src/main/resources/plugin-descriptor.properties</source>
<outputDirectory>/</outputDirectory>
</file>
</files>
</assembly>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2454 次 |
| 最近记录: |