有許多用于檔案操作、過濾、復制等的 Maven 插件。但是還有一種方法可以從 Maven 創建一個新的 XML 檔案(無需創建我自己的插件)?
理想情況下,我可以這樣做:
<build>
<create-file-xml>
<file>${basedir}/src/main/resources/my.xml</file>
<content>
<xml-root>
<any-tags>
${any-variable}
</any-tags>
</xml-root>
</content>
</create-xml-file>
</build>
這樣 ${basedir}/src/main/resources/my.xml 是使用<content>
. my.xml 在我的測驗運行期間應該可用(mvn 測驗)。
uj5u.com熱心網友回復:
您可以嘗試使用來自 Maven 的 antrun 插件。希望您可以根據需要自定義以下代碼。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>add-test-resource</id>
<phase>generate-test-resources</phase>
<configuration>
<target>
<echo file="src/test/resources/output.xml" append="true">
<![CDATA[<xml-root>
hello!!!
</xml-root>]]>
</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/476033.html