Java 如何使用Maven将一个文件注入另一个文件?
我的src/main/resources中有两个文件,我希望将一个文件的主体注入另一个文件的特定位置。因此,一个文件应该是模板,另一个文件将包含填充此模板的数据(类似于ApacheVelocity) 我可以用一些现有的Maven插件来实现这一点吗 先谢谢你 解决方案: 我决定不使用特殊插件,而是将其添加到pom.xml中:Java 如何使用Maven将一个文件注入另一个文件?,java,maven,Java,Maven,我的src/main/resources中有两个文件,我希望将一个文件的主体注入另一个文件的特定位置。因此,一个文件应该是模板,另一个文件将包含填充此模板的数据(类似于ApacheVelocity) 我可以用一些现有的Maven插件来实现这一点吗 先谢谢你 解决方案: 我决定不使用特殊插件,而是将其添加到pom.xml中: <build> <plugins> <plugin> <groupId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>rng-injection</id>
<phase>generate-resources</phase>
<configuration>
<target>
<echo message="Injecting RNG schemes"/>
<copy file="${main.resources}/RNG/enets-template.rng"
tofile="${main.resources}/RNG/enets.rng"
verbose="true"
overwrite="true"/>
<copy file="${main.resources}/RNG/modeldefinition-template.rng"
tofile="${main.resources}/RNG/modeldefinition.rng"
verbose="true"
overwrite="true"/>
<property name="enets-def" value="${main.resources}/RNG/enetsdefinitions.rng"/>
<loadfile property="def-file" srcfile="${enets-def}"/>
<replace file="${main.resources}/RNG/enets.rng">
<replacefilter token="{!enets-definition!}" value="${def-file}"/>
</replace>
<replace file="${main.resources}/RNG/modeldefinition.rng">
<replacefilter token="{!enets-definition!}" value="${def-file}"/>
</replace>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
org.apache.maven.plugins
maven antrun插件
1.6
rng注射
产生资源
跑
我不知道有哪个插件提供了您想要做的事情,但是作为一个开始,您可能能够将主体读入属性,并使用资源过滤将该属性注入第二个文件。有关如何构建插件来做与此相关的事情的示例,请参阅Apache Mahout的collections codegenerator mojo。它是一个使用velocity生成java代码的插件