Can the Eclipse Java formatter be used stand-alone
Asked Answered
O

3

19

Is there a way to use the formatter that comes with eclipse, outside of eclipse? I would like to format some java files using my formatter.xml file that I have configured using eclipse. Does anyone have any code examples that would allow me to do this? I would also like to use this standalone, so the specific jars that are used would be nice.

Ocelot answered 21/12, 2008 at 4:41 Comment(0)
R
12

Apparently you can directly invoke Eclipse's code formatter from the command line.

Rokach answered 21/12, 2008 at 5:16 Comment(4)
This gives a nice explanation of how to invoke the formatter from the command line as well.Stooge
It takes 41 seconds for Eclipse to fire up and do this, it's not an every commit kind of thing.Lonely
link is dead :(Centuplicate
Here's a link to similar material that works, today at least - beyondjava.net/run-eclipse-formatter-command-line.Hammerlock
S
4

Here's the offical eclipse docs on how to do this

Dump of those docs:

Running the formatter application is as simple as running the org.eclipse.jdt.core.JavaCodeFormatter application from the commandline:

eclipse -vm <path to virtual machine> -application org.eclipse.jdt.core.JavaCodeFormatter [ OPTIONS ] <files>

When invoked on MacOS, the paths to point to the configuration file or the source files can be relative, but they will be computed from the location of the eclipse.ini file. This is a limitation of the Eclipse launcher on MacOS. On all other platforms, the relative paths are computed relative to the current user directory.

Java source files and/or directories to format. Only files ending with .java will be formatted in the given directory.

-config

Use the formatting style from the specified properties file. Refer to Generating a config file for the formatter application for details.

-help

Display the help message.

-quiet

Only print error messages.

-verbose

Be verbose about the formatting job.

Smock answered 30/7, 2018 at 13:41 Comment(0)
S
1

Never tried to pull something like that off, but I remember seeing once a class called:

org.eclipse.jdt.core.formatter.CodeFormatterApplication

Perhaps that is some standalone entry point into the formatting mechanism, though I've never tried or investigated further.

Stringpiece answered 21/12, 2008 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.