Eclipse has a powerful code formatter for Java, but I am wondering whether it is possible to define a code format on a per file basis, instead of defining the format for all java files?


  • Can you explain how this might be useful? – Karan Mar 31 '13 at 17:08
  • Well, for example you could use some code from vendor, which uses a different coding style. But sometimes you may need to modify it a little bit. @Karan – xuhdev Apr 24 '13 at 18:56
  • Well Eclipse is going to format as Java based on the file extension, so one possible way might be to rename the ones you want a different/custom format for to some other extension, then define your desired formatting rules for files with that new extension. Of course, changing extensions quite likely will cause issues, so I don't know how else one might do this without undesirable side-effects. Perhaps if there's a way to make Eclipse select different formatting rules based on some unique string inside the Java files. Maybe there's a plugin that does this... – Karan Apr 24 '13 at 20:22

Don't know how to specify a formatter per-file, but there is at least a way to selectively turn formatter off so it doesn't mess up existing formatting, see here:

In short, you can configure Eclipse to look for comments like @formatter:on and @formatter:off, details here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.