Simple of Templating by

Mustache.js is very popular templating js for web. Today we going to look at java version of mustache.

So for getting started we need a file which will act like a template for our program. For this we a file template.mustache which is simple text for a mail with some place holder in mustache syntax.


Hi {{name}},

Your Account number {{accountNo}} mapped with your aardhar card no. {{ uuid}}
Is {{status}}. Thank you for your assistance.
Congrat!!! Now Enjoy the benefits...
Sorry !!! Please try agian

Thank You

Now when we have our template file ready. we going to use this file a template publish mail to a person in java. And just for now it is going to print it in console because this example is just to give an idea about more comprehensive mustache will be covered in later post.

class TestMushache{
    public void main(String... args){
                 MustacheFactory mf = new DefaultMustacheFactory();
         Mustache mustache = mf.compile("template.mustache");
         Map map = new HashMap(){
                 put("name", "TestName");
                 put("accountNo", 123679);
                 put("status", "Failed because invalid information");
                 put("isPassed", 0);
                 put("isFailed", 1);
                 put("sender", "Test Sender");
                mustache.execute(new PrintWriter(System.out), map).flush();



The following is output on the console

Hi TestName,

Your Account number 123679 mapped with your aardhar card no. 101010-101010-10101-0420
Is Failed because invalid information. Thank you for your assistance.

Sorry !!! Please try agian

Thank You
Test Sender


To download jar for the mustache you vist this link.

And the maven dependency is followed below.


Please do comment and share the post.

Share :

Subscribe & Social

Subscribe to this blog via RSS.

Recent Posts


Java 14

Python 2

Wordpress 1

Ops 3

Shared 3

Angular 1

Web 1

Draftblog 1

Popular Tags

Java (14) Python (2) Wordpress (1) Ops (3) Angular (1) Web (1) Draftblog (1)


DGStack is web blog by digvijay bhakuni. This blog is about computer programming tips and trick. And some short tutorial and gettings started post about the framework, libriay, api and much more. The blog target mostly open source stuff like java, j2ee, nodeJs, angularJs, spring, struts, mongodb, mean, etc


This website claims no credit for any images posted on this site unless otherwise noted. Images on this blog are copyright to its respectful owners. If there is an image appearing on this blog that belongs to you and do not wish for it appear on this site, please E-mail with a link to said image and it will be promptly removed. And the information is best of my knowledge one can always write comment or mail regarding information is this blog.