how to format your Java code with eclipse, without opening eclise

Ok this is a very small post, but if you look for this information through Google, for example, it’s hard to find an easy and clear answer. And here it is.

Assuming your eclipse path is /Applications/eclipse/eclipse, and the all the Java code (even in subdirectories) resides in /Users/lorenzo/sources/java_project/, the command is the following:


/Applications/eclipse/eclipse -vm /usr/bin/java -config /Users/lorenzo/mysettings/eclipse/org.eclipse.jdt.core.prefs -application org.eclipse.jdt.core.JavaCodeFormatter -verbose /Users/lorenzo/sources/java_project/*


That’s it.


Of course, this means that the “coding style” is described in the /Users/lorenzo/mysettings/eclipse/org.eclipse.jdt.core.prefs¬†file. A research in your path will display an already existent one.

And, of course, it assumes that you have Eclipse installed.

Leave a Comment

Your email address will not be published. Required fields are marked *