Han*_*etz 13 build-automation maven-2 assemblies
我正在使用Maven及其程序集插件来构建我的项目的分发包,如下所示:
现在,我正在添加另一个解压缩ZIP的项目,将所有其他JAR放入正确的目录中,然后重新打包以进行分发.现在,我的bundle可能包含我要合并到的配置文件,而不是替换运行时程序集中名称相同的配置文件.我怎么做?
这些文件是纯文本(属性文件),但稍后我可能会遇到与XML文件类似的情况.
jwm*_*may 24
在克林斯曼的回答对于那些谁在这个跌跌扩展一点-的containerDescriptorHandler描述符可以采取四个值(V2.3),这些都是metaInf-services,file-aggregator,plexus,metaInf-spring.它有点埋没在代码中(在包中找到org.apache.maven.plugin.assembly.filter)但是可以聚合配置/属性文件.
这是一个示例描述符,用于聚合META-INF/services位于其中的命名属性文件com.mycompany.actions.
descriptor.xml
<assembly>
...
<containerDescriptorHandlers>
    <containerDescriptorHandler>
        <handlerName>metaInf-services</handlerName>
    </containerDescriptorHandler>
    <containerDescriptorHandler>
        <handlerName>file-aggregator</handlerName>
        <configuration>
            <filePattern>com/mycompany/actions/action.properties</filePattern>
            <outputPath>com/mycompany/actions/action.properties</outputPath>
        </configuration>
    </containerDescriptorHandler>
</containerDescriptorHandlers>
....
</assembly>
该file-aggregator可包含一个正则表达式的filePattern匹配多个文件.以下内容将匹配所有文件名'action.properties'.
<filePattern>.+/action.properties</filePattern>
在metaInf-services和metaInf-spring用于聚集SPI分别Spring配置文件,而plexus处理器将聚集META-INF/plexus/components.xml在一起.
如果您需要更专业的东西,可以通过实现ContainerDescriptorHandler和定义组件来添加自己的配置处理程序META-INF/plexus/components.xml.您可以通过创建一个依赖于maven-assembly-plugin并包含自定义处理程序的上游项目来完成此操作.你可能可以在你正在组装的同一个项目中这样做,但我没有尝试过.处理程序的实现可以在org.apache.maven.plugin.assembly.filter.*程序集源代码的包中找到.
CustomHandler.java
package com.mycompany;
import org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler;
public class CustomHandler implements ContainerDescriptorHandler {
    // body not shown
}
然后定义组件 /src/main/resources/META-INF/plexus/components.xml
components.xml中
<?xml version='1.0' encoding='UTF-8'?>
<component-set>
    <components>
        <component>
            <role>org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler</role>
            <role-hint>custom-handler</role-hint>
            <implementation>com.mycompany.CustomHandler</implementation>
            <instantiation-strategy>per-lookup</instantiation-strategy>
        </component>
    </components>
</component-set>
最后,将此添加为您要组装的项目中的程序集插件的依赖项
的pom.xml
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
        <descriptors>
            <descriptor>...</descriptor>
        </descriptors>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>sample-handler</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
</plugin>
并在描述符中定义handlerName
descriptor.xml
...
<containerDescriptorHandler>
    <handlerName>custom-handler</handlerName>
</containerDescriptorHandler>
...
该行家遮阳帘插件还可以创建"尤伯杯罐子",并具有用于处理XML,许可证和舱单一些资源转变.
Ĵ
| 归档时间: | 
 | 
| 查看次数: | 18992 次 | 
| 最近记录: |