Accepted answer

right click on the project root and select source -> format. this should work for at least version 3.8.1. and above.

if the above does not work, you're probably using an older eclipse-version. in such case you can select your source folders by clicking on them while holding down ctrl, then select source -> format from the right-click -menu. works with package-folders and class files also, in case you don't want to format the entire project.


in eclipse mars.1 release (4.5.1) version and above, just press right click on the code typing area

src > source > format.

if you want to format individual java / xml file just do ctrl+shift+f


in older versions of eclipse (indigo) it works from package explorer (not navigator). right click the package you wish to format then choose source -> format. it will format all classes in that package and its sub-packages.


this is the purpose of

source ->clean up...

selecting the appropriate options.


i also had the java perspective on and this was still not working. my eclipse was only formatting css and html files, but not java ones.

then, i located this answer that explains this:

you must add java facet to the project to allow java classes to be detected by eclipse formatter

then, you should check on project-properties-project facets and activate the java facet for the project:

enter image description here

and by right-clicking on top of the package-explorer you will find the source - format option, and it will format java files too.

be careful, check it´s package explorer, not project explorer (click window-show view-packageexplorer)

enter image description here

Related Query

More Query from same tag