By nmb1106


2014-01-24 19:53:26 8 Comments

Eclipse allows the ability for you to customize code formatters and export/import them. Is there a way for me to create a formatter, save it in source control, and set a property somewhere that will load that into eclipse automatically when you open the project?

We want to use a custom formatter but not if it can't be configured automatically through the team. We don't want someone forget to import the formatter and end up formatting the code with another setup. Could only imagine that would create some not so fun conflicts down the road.

2 comments

@J Steven Perry 2014-01-24 20:27:37

As meriton said, you can modify the default formatter used, and it will be saved to your project directory. Specifically the .settings folder to two different files: one file called org.eclipse.jdt.core.prefs that stores the specific formatter instructions, and another "pointer" file called org.eclipse.jdt.ui.prefs that "points" to your modified code formatter.

org.eclipse.jdt.core.prefs looks like:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
(etc)

org.eclipse.jdt.ui.prefs looks like:

eclipse.preferences.version=1
formatter_profile=_Eclipse [modified]
formatter_settings_version=12

Note: I named my modified formatter "modified" (it seemed appropriate). I'm using Kepler, so your mileage may vary, void where prohibited, see dealer for details...

Make sure to save the .settings folder, and these two files to your SCM system (along with your .project file, which will be in the root folder).

Have fun!

@meriton 2014-01-24 20:03:17

Right-click the project, choose "Properties", then "Java -> Formatter", check "enable project specific settings", and configure your formatter however you want. The entire configuration will then be saved in the project directory, which you can easily put under version control.

Related Questions

Sponsored Content

24 Answered Questions

[SOLVED] Does Java support default parameter values?

41 Answered Questions

[SOLVED] How can you speed up Eclipse?

  • 2008-11-25 03:18:56
  • user2427
  • 609956 View
  • 1277 Score
  • 41 Answer
  • Tags:   eclipse performance

44 Answered Questions

[SOLVED] Can't start Eclipse - Java was started but returned exit code=13

12 Answered Questions

17 Answered Questions

[SOLVED] "Debug certificate expired" error in Eclipse Android plugins

12 Answered Questions

8 Answered Questions

[SOLVED] Importing a GitHub project into Eclipse

  • 2011-07-20 09:59:08
  • blue-sky
  • 377752 View
  • 121 Score
  • 8 Answer
  • Tags:   eclipse github

1 Answered Questions

[SOLVED] eclipse formatter not working

  • 2014-06-18 05:37:03
  • user3751014
  • 5304 View
  • 1 Score
  • 1 Answer
  • Tags:   eclipse formatter

2 Answered Questions

[SOLVED] Auto updating formatter in Eclipse

3 Answered Questions

[SOLVED] bind custom code formatter to eclipse project

Sponsored Content