Eclipse默认自定义格式化程序

Eclipse允许您自定义代码格式化程序并导出/导入它们。 有没有办法让我创建一个格式化程序,将其保存在源代码管理中,并在某个地方设置一个属性,当你打开项目时会自动将其加载到eclipse中?

我们想要使用自定义格式化程序,但如果无法通过团队自动配置,则不能。 我们不希望有人忘记导入格式化程序并最终使用其他设置格式化代码。 只能想象这会在未来产生一些不那么有趣的冲突。

右键单击项目,选择“属性”,然后选择“Java – > Formatter”,选中“启用项目特定设置”,然后根据需要配置格式化程序。 然后整个配置将保存在项目目录中,您可以轻松地将其置于版本控制之下。

正如meriton所说,您可以修改使用的默认格式化程序,它将保存到您的项目目录中。 特别是.settings文件夹到两个不同的文件:一个名为org.eclipse.jdt.core.prefs文件,用于存储特定的格式化程序指令,另一个名为org.eclipse.jdt.ui.prefs “指针”文件“指向”修改后的代码格式化程序。

org.eclipse.jdt.core.prefs看起来像:

 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看起来像:

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

注意:我将修改后的格式化程序命名为“已修改”(似乎合适)。 我正在使用开普勒,因此您的里程可能会有所不同,在禁止的地方无效,详见经销商……

确保将.settings文件夹和这两个文件保存到SCM系统(以及.project文件,它将位于根文件夹中)。

玩得开心!