组装Spring Boot项目时如何重命名文件? [英] How can I rename a file when assembling a spring boot project?
问题描述
我有以下assembly.xml.我试图弄清楚在包含文件时如何将它们重命名为其他名称.目前,我的tar的war文件为project-1.0.0.0.war,我希望它为project.war.我该怎么做?
I have the following assembly.xml. I was trying to figure out how when including files I can rename them to something else. Currently, my tar has the war file as project-1.0.0.0.war and I want it to be project.war. How can I accomplish this?
<assembly>
<id>${version}-tar</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>project-${version}</baseDirectory>
<fileSets>
<fileSet>
<directory>target</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>project-${version}.war</include>
</includes>
</fileSet>
<fileSet>
<directory>etc/bin</directory>
<outputDirectory>.</outputDirectory>
<includes>
<include>start</include>
<include>stop</include>
</includes>
</fileSet>
</fileSets>
推荐答案
如果要控制程序集中文件的目标名称,则不应使用 <file>
.原因是第一个文件将多个文件分组在一起,因此无法提供控制组中每个文件名称的方法.由于<file>
仅定位单个文件,因此可以使用<destName>
元素控制目标名称:
If you want to control the destination name of the file in the assembly, you shouldn't use a <fileSet>
, but a <file>
. The reason is that the first groups several files together, and as such, doesn't provide a way to control the name of each file in the group. Since a <file>
targets only a single file, you can control the destination name with the <destName>
element:
在outputDirectory中设置目标文件名.默认名称与源文件的名称相同.
Sets the destination filename in the outputDirectory. Default is the same name as the source's file.
您应该改为:
<files>
<file>
<source>target/project-${version}.war</directory>
<destName>project.war</destName>
</file>
</files>
<!-- the other "fileSets" for etc/bin, unchanged -->
而不是<fileSet>
.这样可以确保将<source>
元素中指定的文件在生成的程序集中重命名为<destName>
.
instead of the <fileSet>
. This will make sure that the file specified in the <source>
element is renamed to <destName>
in the resulting assembly.
这篇关于组装Spring Boot项目时如何重命名文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!