Eclipse为什么会将M2_REPO添加到Java Build Path > Libraries > Classpath中?

huangapple go评论53阅读模式
英文:

Why does Eclipse add M2_REPO to Java Build Pat > Libraries > Classpath?

问题

Eclipse会自动将M2_REPO/...添加到项目的属性 > Java构建路径 > 类路径下。以下是一张显示这一点的图片。

Eclipse为什么会将M2_REPO添加到Java Build Path > Libraries > Classpath中?

相反,我希望在类路径下只看到Maven依赖项。这样可以轻松地为所有依赖项设置外部注解和其他属性,而不是逐个设置。以下是显示我想要的内容的图片。

Eclipse为什么会将M2_REPO添加到Java Build Path > Libraries > Classpath中?

我可以手动更正类路径,但以后Eclipse可能会将其恢复。我如何让Eclipse保持较小的类路径?

英文:

Eclipse will automatically add M2_REPO/... to the Project > Properties > Java Build Path > Libraries > Classpath. Here is a picture showing this.

Eclipse为什么会将M2_REPO添加到Java Build Path > Libraries > Classpath中?

Instead, I would like to only see Maven Dependencies under Classpath. This makes it easy to set the External Annotations and other properties for all the dependencies instead of one by one. Here is a picture showing what I want.

Eclipse为什么会将M2_REPO添加到Java Build Path > Libraries > Classpath中?

I can correct the Classpath manually, but at some point later Eclipse will revert it. How do I make Eclipse maintain the smaller Classpath?

答案1

得分: 1

以下是翻译好的部分:

首先,如果有任何问题,您不应该使用"mvn eclipse:eclipse"。众所周知,这是过时的,它会生成正是您试图摆脱的不便结构。

对于m2e尚未完全弄清楚的项目,我的一般策略是从工作区中删除项目(不删除源代码),然后重命名".classpath"文件,添加".bak",然后重新导入项目。通常会产生一个合理的.classpath文件。

不幸的是,我还发现有些项目m2e根本无法理解,导入操作无法正确创建.classpath文件。我尝试提交了一个问题报告,但很难创建一个既能复制问题又能在问题中发布的项目,因此我会说这个问题从未得到解决。在那些罕见的情况下,由于我们所有的项目都有类似的结构,这就是我从一个正常工作的项目中复制/粘贴.classpath到有问题的项目中,有时进行一些微小的编辑。每次都有效。

英文:

First of all, if there's any question, you should never use "mvn eclipse:eclipse". It is well-known that that is obsolete, and it will produce exactly the inconvenient structure you are trying to get away from.

My general strategy with a project that m2e hasn't quite figured out is to delete the project from the workspace (don't delete the source), and then rename the ".classpath" file, adding ".bak" to it, then reimporting the project. That generally will result in a sane .classpath file.

Unfortunately, I also find that there are some projects that m2e just cannot figure out, and the import just punts on creating the .classpath file correctly. I have tried to file an issue for that, but it's too hard to produce a project that both reproduces it and which I can publish in the issue, so I'd say the issue has never been addressed. In those rare cases, as all of our projects are structured similarly, that's when I just cut/paste the .classpath from a working project into the bad one, sometimes with some minor edits. Works every time.

huangapple
  • 本文由 发表于 2023年4月1日 01:07:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75901055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定