当我运行 Ant 构建时,MyEclipse 正在格式化我的 Java 代码

发布于 2024-09-14 21:56:40 字数 870 浏览 3 评论 0原文

当我运行 Ant 构建时,MyEclipse(适用于 v6.0 和 7.5)会格式化我的代码。当我打开文件时,它说它在文件系统上被修改,当我重新加载它时,它被格式化。

更奇怪的是,它的格式不符合我的首选项中代码样式中指定的格式(看起来像 Java Sun 编码规则)。

据我所知,Ant 构建没有调用任何东西来进行格式化,所以 MyEclipse 会这样做吗?可以是插件什么的吗?

构建的一部分还包括 Maven 任务,那么是否有 Maven 插件可以执行此操作?

我提到我在 IDE 的首选项中搜索并停用了所有可能的选项,试图找到一些设置,但什么也没找到。

到目前为止,这非常烦人,并且可能会导致问题,因为我正在处理一些较旧的项目,对代码进行了很少的修改,并且不希望仅仅因为我修改了一个单词或其他东西而得到一个完全混乱的类版本。

还有其他人遇到过这个吗?

PS 它只发生在我的电脑上。我的同事没有遇到这个问题。

谢谢你!

编辑:我已经执行了一些测试:

  1. 我在外部执行了Ant脚本 eclipse(在命令提示符下)然后 用记事本打开文件。这 文件未受影响,未格式化 发生。如果我打开 eclipse 什么也没有 发生在文件上。
  2. 我打开eclipse并使用记事本更改了磁盘上的文件(添加了一些空格并保存)。 Eclipse 表示文件系统上的文件已更改并要求重新加载它们。我说是的,他打开了文件。文件未更改。不会发生格式化。
  3. 我从 eclipse 运行 Ant。 Eclipse 表示文件已更改并要求重新加载它们。我说“是”,当文件打开时,它们就会被格式化。卧槽??!?!!

是否有一个配置说要在 ant 构建之后运行一些任务或其他什么?我找不到任何东西。

When I run an Ant build, MyEclipse (happens for v6.0 and 7.5) formats my code. When I open the file it says it was modified on the file system and when I reload it it is formatted.

The thing that is even stranger is that it is not formatted as specified in the Code Style in my Preferences (seems like Java Sun codding rules).

As far as I could determine, there is nothing called by the Ant build to do the formatting so it MyEclipse doing it? Could it be a plugin or something?

Part of the build also includes Maven tasks so could there be a Maven plugin doing this?

I mention that I searched and deactivated all possible options in the preferences of the IDE trying to find some setting but nothing.

It is very annoying so far and could cause problems since I am working on some older projects with minimal modifications in the code and don't want to have a complete messed up version of a class just because I modified a word or something.

Has someone else encountered this?

P.S. It happens only on my PC. My colleagues don't encounter this issue.

Thank you!

EDIT: I have executed some tests:

  1. I executed the Ant script outside of
    eclipse (in command prompt) then
    opened the files with notepad. The
    files are untouched, no formatting
    occurred. If I open eclipse nothing
    happens to the files.
  2. I opened eclipse and changed the files on the disk using notepad (added some spaces and saved them). Eclipse says the files are changed on the file system and asks to reload them. I say Yes he opens the files. The files are unchanged. No formatting occurs.
  3. I run Ant from eclipse. Eclipse says files have changed and asks to reload them. I say Yes and when the files are opened they are formatted. WTF??!?!!

Is there a config that says to run some tasks after ant builds or something? I could not find anything.

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

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

发布评论

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

评论(2

掩饰不了的爱 2024-09-21 21:56:40

您是否检查了“保存操作”?

“首选项”菜单,Java > 编辑器 > 保存操作。

可能的操作之一是在保存时格式化代码。您可以在全局或每个项目上下文中使用这些首选项。

尽管奇怪的是,当您保存代码时,代码会发生更改运行您的 Ant 脚本。

Did you check the "Save actions"?

Preferences" menu, Java > Editor > Save actions.

One of the possible actions is to format your code when you save. You can have these preferences on a global or per project context.

Although it's strange that the code gets changed when you run your Ant script.

十级心震 2024-09-21 21:56:40

如果您选择,Eclipse 可以在保存时格式化,并且您可以选择让它在构建之前自动保存任何修改的文件。 myeclipse 中没有任何内容会导致代码在加载时格式化。我会查看你的插件。

Jalopy 有一个 ANT 插件,可以格式化代码

Eclipse can format on save if you choose, and you can elect to have it save automatically any modified files before a build. There is nothing in myeclipse that would cause the code to be formatted on load. I would look through your plugins.

Jalopy has an ANT plugin that will format code

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