在maven程序集中复制文件
我正在构建一个maven组件。结构如下:在maven程序集中复制文件,maven,maven-assembly-plugin,Maven,Maven Assembly Plugin,我正在构建一个maven组件。结构如下: src main server app1 app2 app3 client app1 app2 app3 common server.xml 程序集将输出为: server.zip app1 app2 app3 我想在应用程序的每个输出文件夹中包含server.xml。因此,我的输出应该是: server.zip app1
src
main
server
app1
app2
app3
client
app1
app2
app3
common
server.xml
程序集将输出为:
server.zip
app1
app2
app3
我想在应用程序的每个输出文件夹中包含server.xml
。因此,我的输出应该是:
server.zip
app1
server.xml
app2
server.xml
app3
server.xml
如何执行此操作?您需要复制文件
server.xml
,方法是在assembly.xml
中多次声明该文件。下面是一个示例程序集描述符:
。调用Velocity是使用完成的
示例velocity模板(另存为src/main/common/assembly server.xml.vm
):
服务器
拉链
#foreach($i in[1..50])
src/main/server/app$i
应用程序$i
#结束
#foreach($i in[1..50])
src/main/common/server.xml
应用程序$i
#结束
插件配置:
com.googlecode.velocity-maven-plugin
velocity maven插件
1.1.0
生成服务器程序集
产生资源
速度
/src/主/通用
assembly-server.xml.vm
.vm
这将在target
下生成一个assembly server.xml
文件,您可以将其用作maven程序集插件的程序集描述符
for-loop?@user2230605的概念并不简单,但不能直接使用。过去为了解决这个问题,我使用了一个Velocity模板来生成正确的Maven组件。如果您需要示例配置,我将更新我的答案。谢谢,请更新。我正在考虑使用sbt,因为它很容易在那里编写插件。@user2230605如果解决了您的问题,请投票并接受这个答案。
<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>server</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
#foreach($i in [1..50])
<fileSet>
<directory>src/main/server/app$i</directory>
<outputDirectory>app$i</outputDirectory>
</fileSet>
#end
</fileSets>
<files>
#foreach($i in [1..50])
<file>
<source>src/main/common/server.xml</source>
<outputDirectory>app$i</outputDirectory>
</file>
#end
</files>
</assembly>