Maven concat 文件目录中的特定文件
Maven concat files specific files in a directory
我有一个深度和文件夹名称未知的目录。
>A
-> AB
--> configuration.xml
--> ABC
---> configuration.xml
-> AD
--> configuration.xml
-> allconfigurations.xml
我需要一个 Maven 插件来连接所有 configuration.xml
文件并在根目录中创建 allconfigurations.xml
文件。不幸的是,文件夹名称和深度未知。最好在 pom.xml
文件中完成它而不需要任何其他文件。
为您快速 google:maven-shade-plugin 和 XmlAppendingTransformer 可能会有所帮助。
示例配置为 here
虽然挣扎,但我意识到真正的问题是为编译后的 allconfigurations.xml
文件添加页眉和页脚,因为每个 configuration.xml
文件都是一个片段,当我将它们连接在一起时会产生xml 不是有效的 xml。
情况是这样的;
xml 文件类似于:
<Configuration xmlns="abc">
...
<connectionTimeoutInMs>240000</connectionTimeoutInMs>
<socketTimeoutInMs>240000</socketTimeoutInMs>
<persist>false</persist>
<internal>false</internal>
...
</Configuration>
并且放置其中许多是无效的,因此结果 xml 必须类似于;
<AllConfigurations xmlns="abc">
...
<Configuration xmlns="abc">
...
</Configuration >
...
<AllConfigurations xmlns="abc">
因此必须将第一行和最后一行添加到结果中。
这是我想出的解决方案;
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>default-cli</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<!--<phase>process-resources</phase>-->
<!--<phase>compile</phase>-->
<configuration>
<target>
<concat destfile="${project.basedir}/.../allConfigurations.xml"
force="yes">
<fileset dir="${project.basedir}/...">
<include name="xmlHeaderForConfiguration"></include>
</fileset>
<fileset dir="${project.basedir}/...">
<include name="**/configuration.xml"></include>
</fileset>
<fileset dir="${project.basedir}/...">
<include name="xmlFooterForConfiguration"></include>
</fileset>
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
其中 xmlHeaderForConfiguration 是一个包含内容的文件; <AllConfigurations xmlns="abc">
和 xmlHeaderForConfiguration 有 </AllConfigurations>
我有一个深度和文件夹名称未知的目录。
>A
-> AB
--> configuration.xml
--> ABC
---> configuration.xml
-> AD
--> configuration.xml
-> allconfigurations.xml
我需要一个 Maven 插件来连接所有 configuration.xml
文件并在根目录中创建 allconfigurations.xml
文件。不幸的是,文件夹名称和深度未知。最好在 pom.xml
文件中完成它而不需要任何其他文件。
为您快速 google:maven-shade-plugin 和 XmlAppendingTransformer 可能会有所帮助。
示例配置为 here
虽然挣扎,但我意识到真正的问题是为编译后的 allconfigurations.xml
文件添加页眉和页脚,因为每个 configuration.xml
文件都是一个片段,当我将它们连接在一起时会产生xml 不是有效的 xml。
情况是这样的; xml 文件类似于:
<Configuration xmlns="abc">
...
<connectionTimeoutInMs>240000</connectionTimeoutInMs>
<socketTimeoutInMs>240000</socketTimeoutInMs>
<persist>false</persist>
<internal>false</internal>
...
</Configuration>
并且放置其中许多是无效的,因此结果 xml 必须类似于;
<AllConfigurations xmlns="abc">
...
<Configuration xmlns="abc">
...
</Configuration >
...
<AllConfigurations xmlns="abc">
因此必须将第一行和最后一行添加到结果中。
这是我想出的解决方案;
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>default-cli</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<!--<phase>process-resources</phase>-->
<!--<phase>compile</phase>-->
<configuration>
<target>
<concat destfile="${project.basedir}/.../allConfigurations.xml"
force="yes">
<fileset dir="${project.basedir}/...">
<include name="xmlHeaderForConfiguration"></include>
</fileset>
<fileset dir="${project.basedir}/...">
<include name="**/configuration.xml"></include>
</fileset>
<fileset dir="${project.basedir}/...">
<include name="xmlFooterForConfiguration"></include>
</fileset>
</concat>
</target>
</configuration>
</execution>
</executions>
</plugin>
其中 xmlHeaderForConfiguration 是一个包含内容的文件; <AllConfigurations xmlns="abc">
和 xmlHeaderForConfiguration 有 </AllConfigurations>