Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:41:17+00:00 2026-06-18T14:41:17+00:00

Recently I wrote some tools that help me generate Java code for what would

  • 0

Recently I wrote some tools that help me generate Java code for what would otherwise be long and tedious tasks. I use freemarker to write up templates. However, all whitespace in the templates is preserved in the output, resulting in quite messy code. I could remove indentation from my templates to fix this, but that makes my templates rather unmaintainable.

Consider this simple example template:

public class MyTestClass
{
    <#list properties as p>
        private String ${p.name};
    </#list>
}

My template is nicely formatted, but my code comes out as this:

public class MyTestClass
{
        private String prop1;
        private String prop2;
        private String prop3;
}

Indentation is a bit too much, it should be:

public class MyTestClass
{
    private String prop1;
    private String prop2;
    private String prop3;
}

To accomplish this, I have to remove indentation from my template like this:

public class MyTestClass
{
    <#list properties as p>
    private String ${p.name};
    </#list>
}

For this simple case it is not really a problem to remove indentation from my template, but you could imagine complex templates to become quite unreadable.

On the one side I really want my code to be nicely formatted, but on the other side I’d like my templates to be nicely formatted as well. I use Eclipse as IDE, with is built-in formatter fully customized to my (and my team’s) wishes. It would be great if I could somehow generate code from freemarker templates and as a post processing step format its output with Eclipse’s formatter.

I can of course run the formatter manually after generating my code, but I really want to automate this process.

So, long story short, does anyone know how I can use Eclipse’s code formatter within my own Java code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:41:18+00:00Added an answer on June 18, 2026 at 2:41 pm

    If you want to use the Eclipse formatter from your own java code I suggest you take a look at
    the maven java formatter plugin.

    It’s a maven plugin that can be used to format source code based on Eclipse code formatting settings files.

    If you don’t want to use maven but want to embed the formatting code in your own code, take a look at the FormatterMojo. It contains the code that launches the Eclipse Code Formatter (using the Eclipse libraries)

    It’s all free and open-source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wrote some data access methods (plain old Java) that use immutable objects
I recently wrote code that didnt work as i would expect, it was: message
I recently wrote some code that uses the same unsigned short to store two
I recently wrote some Javascript code to generate random fake stock data as I
I'm refactoring some code that a friend wrote and recently stumbled across this function:
I recently wrote some javascript code that filled a drop down list based on
Recently a co-worker of mine wrote in some code to catch a null pointer
So I recently wrote a java class that extends exception and used an instance
Recently wrote some JavaScript code, but there has been a memory leak in IE7.Are
Recently I've added some load-balancing capabilities to a piece of software that I wrote.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.