0

I am new to Freemarker and writing a new Software. Before starting of any functionality, I want to get a complete folder structure to be created dynamically on the basis of user input (like Project Name, package name etc.) But I am not able to find any better way to achieve this.

Here is the structure which I am looking for.

myProject
│   config.json
│   pom.xml
│
└───src
    └───main
        ├───server
        │       server-config.xml
        │
        └───resources
            │   server-artifact.properties
            │
            └───api
                    api.json

I managed to generate server-config.xml with some dynamic values using Freemarker but not able to understand that how can I process these folders/files recursively. And also where should I be maintaining this project structure meta-data so that if there is any change in this structure then program should be able to adapt that change and generate those basic files/folders dynamically.

Thanks in advance.

Ashish
  • 341
  • 2
  • 7
  • 17
  • I think Maven should help you manage your project, there are pre-defined Maven archetype that helps setup purpose-oriented projects with initiated folder strucrure and configs and properties files. – Cortex Jun 06 '20 at 16:47
  • I guess your FMPP "source root directory" has the same directory structure under it than the one you are showing. So I guess that's easy so far. What's dynamic in the directory structure? (If only that some files are optional, the containing directories will only be generated if there's an output file in them.) – ddekany Jun 06 '20 at 19:21
  • @Cortex, Actually we have to remove the maven part here and that is the reason , I am working to Freemarker to achieve what we were achieveing from Maven Archetype. – Ashish Jun 07 '20 at 09:49
  • @ddekany, I downloaded fmpp jars. Now, I am trying to generate the same structure (what is mentioned in question). But getting confused if I should go with FMPP (because of ease of putting template details in one config file) or simply Freemarker can do the trick. I searched much in Google but not getting any concrete example to achieve this. – Ashish Jun 07 '20 at 10:01
  • Most things you see in the FMPP documentation is not part of FreeMarker (as otherwise they were documented in the FreeMarker documentation). FreeMarker knows nothing about traversing a source directory, generating actual files/directories, has no mechanism to define the data-model in configuration files, etc. So if the approach of FMPP fits your problem well, it's faster to use that. If it doesn't, then it's better to write your own application that depends on FreeMarker. – ddekany Jun 08 '20 at 11:58
  • @ddekany, thanks for clarifying this. But as I mentioned that I am new to freemarker/fmpp, so any example in FMPP using Java where FMPP is traversing directories would be helpful. – Ashish Jun 08 '20 at 12:37
  • @Ashish You mean, you want to invoke FMPP from Java, not from command-line (or from Ant). These things are called front-ends in the FMPP documentation. See http://fmpp.sourceforge.net/writefrontend.html – ddekany Jun 08 '20 at 16:58
  • Thanks @ddekany , this is what I was looking for. Just a question, can we create directories in Freemarker/FMPP if those directories do not exist? – Ashish Jun 09 '20 at 05:39
  • 1
    @Ashish Not sure how the use case looks, but sometimes you can. Like, of you can change the output path of a file with the `pp.renameOutputFile` directive, and then its output directory will be automatically created for it. – ddekany Jun 10 '20 at 23:48

0 Answers0