In case you needed to format a batch of code using a command line utility, you probably went for Jalopy or JIndent. Thanks to Ben Konrath of Red Hat, you no longer need to do so: since Eclipse 3.2, you can use the built-in code formatter to format your Java code using the command line.
The hardest part of it all is to create the config file for the formatter. To create it, select one of your existing projects, and activate project specific formatter settings (Properties –> Java Code Style –> Formatter –> Enable project specific settings):
Configure the code formatter as desired. Click OK when you’re done.
Using a file explorer, navigate to
To invoke the code formatter using the command line issue the following command:
<path-to-eclipse>\eclipse.exe -vm <path-to-vm>\java.exe -application **org.eclipse.jdt.core.JavaCodeFormatter** -verbose -config <path-to-config-file>\org.eclipse.jdt.core.prefs <path-to-your-source-files>\*.java
In case the formatter complains about your code, your code probably contains Java 5 constructs and you have to add the following lines to your config file to make everything work: