使用m2e时的Eclipse项目配置

发布于 2025-01-03 09:06:44 字数 484 浏览 2 评论 0原文

我们的工作使用 maven/m2e/eclipse 组合。我们首先在 eclipse 中导入 master maven pom 文件,然后导入我们的项目。我们的源代码控制系统设置为忽略 Eclipse 生成的项目文件,因为我们不想签入生成的任何内容。一切都很顺利,这方面没有问题。

我们想要做的是为所有项目设置一些通用的 eclipse 首选项,以确保所有开发人员的标准编码风格并遵循 java 最佳实践。示例是在 Eclipse 中重新组织导入设置、保存文件时重新格式化代码以及标准行宽(我们更喜欢 120 个字符,而不是标准 80 个 Eclipse 默认值)

似乎可以使用项目配置器将 m2e 配置为生成其中一些设置,但也可以找不到任何例子。

我们有什么想法可以实现这个功能吗?如果能从 Maven pom 配置生成项目特定条目,并且每个人都将自动共享相同的设置,那就更好了。

我不介意为 m2extension 编写一些代码,但我不熟悉 eclipse 的内容,也不知道需要做什么。

We use maven/m2e/eclipse combo for our work. We start with importing master maven pom file in eclipse and our projects get imported. Our source control system is set up to ignore eclipse generated project files as we don't want to check in anything generated. It all works nicely and not problems on this end.

What we would like to do is set up some common eclipse preferences for all the projects to ensure standard coding style across all developers and follow java best practices. Example is reorganize imports setting in eclipse, reformat code when file is saved, and standard line widths (we prefer 120 characters as against standard 80 eclipse default)

It seems like m2e can be configured to generate some of these settings using project configurator, but could not find any examples.

Any thoughts how we can achieve this functionality? It would be much nicer to have project specific entries generated from maven pom configuration and everyone will share same settings automatically.

I don't mind writing some code for the m2extension, but I am not familiar with eclipse guts and don't know what needs to be done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2025-01-10 09:06:44

我不确定是否通过 m2e 执行此操作,但您可以从 Eclipse 导出代码格式化程序,并指导新开发人员在设置时导入它;我过去正是这样做的,它导致了一致的编码风格(有时脾气暴躁的开发人员,请注意!)。

在 Eclipse 中,转到

“窗口”->“首选项-> Java->代码风格->格式化程序

并创建一个配置文件来定义您希望 Java 的外观。然后在该配置文件上选择“编辑”,您将在右上角看到一个“导出”选项,这将生成一个 XML 文件。将其签入您的存储库中的某处或以其他方式将其分发给您的开发人员,他们可以以类似的方式导入它。然后每次按 ctrl+shift+f 时,它们都会以相同的方式进行格式化。

更多帮助请参见:Eclipse Indigo Java 代码格式化程序

I'm not sure about doing this through m2e, but you can Export your code formatter from Eclipse, and instruct new developers to import it when they get set up; I've done exactly this in the past and it leads to a consistent coding style (and sometimes grumpy developers, be warned!).

In Eclipse, go to

Window -> Preferences -> Java -> Code Style -> Formatter

and create a profile that defines just how you like your Java to look. Then select Edit on that profile, and you'll see an option in the top right to Export, which will produce an XML file. Check this into your repository somewhere or otherwise distribute it to your developers, and they can import it in a similar way. Then each time they press ctrl+shift+f they'll all be formatting the same way.

More help here: Eclipse Indigo Java Code Formatter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文