How do I use a template code generator (eg freemarker) in Maven?

后端 未结 2 2010
终归单人心
终归单人心 2021-02-19 14:55

How would you structure Freemarker (or an alternative) as a templating code generator into a Maven project? I\'m pretty new to Maven and would appreciate some help.

I wa

2条回答
  •  抹茶落季
    2021-02-19 15:54

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

    Heres the fragment from pom.xml highlighting its usage:

    
        
            
                src/test/resources/freemarker/config.fmpp
                target/test/generated-sources/fmpp/
                src/test/resources/fmpp/
            
            com.googlecode.fmpp-maven-plugin
            fmpp-maven-plugin
            1.0
            
                
                    generate-sources
                    
                        generate
                    
                
            
        
    
    

    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.

提交回复
热议问题