Batch Formatting of Java Source Files with Eclipse

Sometimes it is helpful to format a whole batch of Java source files in the same style your eclipse source formatter is configured. This is for example very helpful if you have to merge two development branches and you want to format the source files of both branches before comparing them to remove unimportant differences between both branches.
The eclipse source formatter has a hidden feature that allows it to be run on a directory of java files with a simple shell command:
eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -verbose


  • <PATH_TO_CONFIG_FILE>: Path to the properties file containing the configuration of the code formatter. This file is created in .settings/org.eclipse.jdt.core.prefs when you configure the formatter in eclipse for a specific project
  • <PATH_TO_JAVA_SOURCES>: Path to the folder containing the java source files to format.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s