How to access Java system properties from Freemarker templates?

非 Y 不嫁゛ 提交于 2019-12-05 22:57:25

FMPP has a setting called data that specifies the variables that all templates will see, so that's where you should put the system properties. To put values into there, unless the value can be specified as a simple literal, you need a so called data-loader. So in this case you need a data-loader that returns the system properties as a java.util.Properties object. While there's no data-loader specifically for that, you can use the eval data-loader like this (in your config.fmpp):

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

Now in your templates you can access the system properties like sysProps["os.name"].

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

cf https://community.jivesoftware.com/thread/14820

You can access it like this :

${statics['java.lang.System'].getProperty("my.property")}

cf documentation here : http://freemarker.sourceforge.net/docs/pgui_misc_beanwrapper.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!