且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Maven中使用模板代码生成器(例如,freemarker)?

更新时间:2022-01-25 01:37:13

我为此目的编写了一个maven插件.它使用FreeMarker预处理器.

I had written a maven plugin for this purpose. It uses the FreeMarker Pre Processor.

在pom.xml的片段中突出显示了其用法:

Heres the fragment from pom.xml highlighting its usage:

<plugins>
    <plugin>
        <configuration>
            <cfgFile>src/test/resources/freemarker/config.fmpp</cfgFile>
            <outputDirectory>target/test/generated-sources/fmpp/</outputDirectory>
            <templateDirectory>src/test/resources/fmpp/</templateDirectory>
        </configuration>
        <groupId>com.googlecode.fmpp-maven-plugin</groupId>
        <artifactId>fmpp-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

在此cfgFile是保存FMPP的配置文件的路径. (如果您不使用FreeMarker中传递的任何特殊数据,那么一个空文件就足够了) templateDirectory是保存FreeMarker模板的位置. outputDirectory是您要在其中生成输出文件的地方.

Here the cfgFile is the path where you keep the config file for FMPP. (if you are not using any special data passing in FreeMarker then an empty file will be enough) templateDirectory is where you keep the FreeMarker templates. outputDirectory is where you want the output files to be generated.

我正在写详细的文档,突出显示插件的用法,并将更新项目网站.

I am in process of writing a detailed documentation highlighting the plugins usage and will update the project website accordingly.