Eclipse:Maven 搜索依赖项不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14059685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:29:24  来源:igfitidea点击:

Eclipse : Maven search dependencies doesn't work

eclipsemavenmaven-pluginmaven-dependency-plugin

提问by Majid Laissi

I created a new simple Maven project in a new Workspace.

我在新的工作区中创建了一个新的简单 Maven 项目。

When I open the pom.xml's Dependenciesview in Eclipse editor, and I choose Add..dependency, there's no search results no matter what search criteria I input in the search fields:

当我在 Eclipse 编辑器中打开pom.xml'sDependencies视图并选择Add..依赖项时,无论我在搜索字段中输入什么搜索条件,都没有搜索结果:

It instantly give me, for example, Results for 'spring' (0).

例如,它立即给我Results for 'spring' (0)

In my other workspace, with my existing projects I don't have this problem.

在我的另一个工作区中,我现有的项目没有这个问题。

Is there a way to fix that ?

有没有办法解决这个问题?

回答by Xiujun Ma

Eclipse artifact searching depends on repository's index file. It seems you did not download the index file.

Eclipse 工件搜索取决于存储库的索引文件。您似乎没有下载索引文件。

Go to Window -> Prefrences -> Mavenand check "Download repository index updates on start". Restart Eclipse and then look at the progress view. An index file should be downloading.

转到Window -> Prefrences -> Maven并检查“在启动时下载存储库索引更新”。重新启动 Eclipse,然后查看进度视图。应该正在下载索引文件。

After downloading completely, artifact searching will be ready to use.

下载完成后,神器搜索就可以使用了。

Maven Settings

Maven 设置

UPDATEYou also need to rebuild your Maven repository index in 'maven repository view'.

更新您还需要在“Maven 存储库视图”中重建您的 Maven 存储库索引。

In this view , open 'Global Repositories', right-click 'central', check 'Full Index Enable', and then, click 'Rebuild Index' in the same menu.

在此视图中,打开“全局存储库”,右键单击“中央”,选中“启用完整索引”,然后在同一菜单中单击“重建索引”。

A 66M index file will be downloaded.

将下载一个 66M 的索引文件。

Maven Repositories ->Rebuild Index

Maven 存储库 ->重建索引

回答by Hetal Rachh

In your eclipse, go to Windows -> Preferences -> Maven Preferences Maven ScreenshotTick the option "Download repository index updates on startup". You may want to restart the eclipse.

在您的 Eclipse 中,转到 Windows -> Preferences -> Maven 偏好设置 Maven 截图勾选选项“在启动时下载存储库索引更新”。您可能需要重新启动日食。

Also go to Windows -> Show view -> Other -> Maven -> Maven repositories Maven Repository View Screenshot

也去 Windows -> Show view -> Other -> Maven -> Maven repositories Maven 存储库视图屏幕截图

On Maven repositories panel, Expand Global repositories then Right click on Central repositories and check "Full index enabled"option and then click on "Rebuild index".

在 Maven 存储库面板上,展开全局存储库,然后右键单击中央存储库并选中“启用完整索引”选项,然后单击“重建索引”

Full Index Screenshot

完整索引截图

回答by Lee Meador

You can get this result if you are inside a corporate proxy and the new project isn't pointing to the correct settings.xml file with the proxy credentials.

如果您在公司代理内部并且新项目没有使用代理凭据指向正确的 settings.xml 文件,则您可以获得此结果。

You can also get this if you are using Maven proxy (Nexus, for example) and the index into the proxy is messed up somehow. I don't know a way to describe how to fix this. Fool around with it or call the one who set up the Maven proxy.

如果您使用 Maven 代理(例如 Nexus)并且代理中的索引不知何故弄乱了,您也可以获得此信息。我不知道如何描述如何解决这个问题。愚弄它或打电话给设置 Maven 代理的人。

You can also get this if the new workspace hasn't yet downloaded the index either from Maven central or from the proxy. (This is the best one as you just have to wait a while and it will work itself out.)

如果新工作区尚未从 Maven 中心或代理下载索引,您也可以获得此信息。(这是最好的,因为你只需要等待一段时间,它就会自行解决。)

回答by Tian Hu

The maven add dependency is actually from the maven indexes. If the indexes is up to date, the result should be from there.

maven add 依赖实际上来自 maven 索引。如果索引是最新的,则结果应该来自那里。

If you go to the maven repository, then select global repository, you should see a central ... tab, and select that, there should be a list of folders, and you should be able to see all the indexes from there. If not, then it means you didn't get the full index, then you can right click that and enable full index.

如果您转到 maven 存储库,然后选择全局存储库,您应该会看到一个中央 ... 选项卡,然后选择它,应该有一个文件夹列表,您应该能够从那里看到所有索引。如果没有,则表示您没有获得完整索引,然后您可以右键单击并启用完整索引。

Another thing I annoyed me most is even I did everything, it still not showing anything when I type "spring". This is actually where I did wrong. If you just type some additional text "springframework", BOOM, the result is there.

最让我恼火的另一件事是,即使我做了所有事情,当我输入“spring”时它仍然没有显示任何内容。这实际上是我做错的地方。如果你只是输入一些额外的文本“springframework”,BOOM,结果就在那里。

回答by Pavel

For me for this issue worked to:

对我来说,这个问题有助于:

  • remove ~/.m2
  • enable "Full Index Enabled" in maven repository view on central repository
  • "Rebuild Index" on central maven repository
  • 删除 ~/.m2
  • 在中央存储库的 Maven 存储库视图中启用“启用完整索引”
  • 中央 Maven 存储库上的“重建索引”

After eclipse restart everything worked well.

eclipse重启后一切正常。

回答by arpi

I have the same problem. None of the options suggested above worked for me. However I find, that if I lets say manually add groupid/artifact/version for org.springframework.spring-core version 4.3.4.RELEASE and save the pom.xml, the dependencies download automatically and the search works for the jars already present in the repository. However if I now search for org.springframework.spring-context , which isnt in the current dependencies, this search still doesn't work.

我也有同样的问题。上面建议的选项都不适合我。但是我发现,如果我可以说为 org.springframework.spring-core 版本 4.3.4.RELEASE 手动添加 groupid/artifact/version 并保存 pom.xml,则依赖项会自动下载并且搜索已经存在的 jars在存储库中。但是,如果我现在搜索不在当前依赖项中的 org.springframework.spring-context ,则此搜索仍然无效。

回答by user1050755

Use https://search.maven.org/manually with the prefix fc: to search for class names. Both Netbeans and Eclipse seem to be too stupid to use that search interface and the gigabytes of downloaded repository indexes seem to not contain any class information. Total waste of disk space. Those IDE projects are so badly maintained lately, I wish they would move development to GitHub.

手动使用https://search.maven.org/前缀 fc: 来搜索类名。Netbeans 和 Eclipse 似乎都太愚蠢了,无法使用该搜索界面,下载的存储库索引的千兆字节似乎不包含任何类信息。完全浪费磁盘空间。那些 IDE 项目最近维护得非常糟糕,我希望他们将开发转移到 GitHub。

回答by Sati

It is neccesary to provide Group Id and Artifact Id to download the jar file you need. If you want to search it just use * , * for these fields.

需要提供 Group Id 和 Artifact Id 才能下载您需要的 jar 文件。如果您想搜索它,只需对这些字段使用 * , * 。