How to access Java system properties from Freemarker templates?

I started using Freemarker to build simple HTML pages using the FMPP Maven plugin . So far, so good. But I just need to add the value of the system property (one of the system properties that Maven provides) on the page. Is there a way to access system properties from Freemarker templates? (if not, I can just hack the plugin to pass values ​​from Maven)

+3
source share
2 answers

FMPP has a parameter calleddata , which indicates the variables that all templates will see, so you must put the properties of the system. To put values ​​there, if the value cannot be specified as a simple literal, you need a so-called data loader. Therefore, in this case, you need a data loader that returns the properties of the system as an object java.util.Properties. Although there is no special data loader for this, you can use a data loader evallike this (in yours config.fmpp):

data: {
   ...
   sysProps: eval('System.getProperties()')
   ...
}

Now in your templates you can access system properties, for example sysProps["os.name"].

Alternatively, you can write a custom FMPP data loader. See http://fmpp.sourceforge.net/dataloader.html#sect19 .

+2

All Articles