Maven Dependency Search Not Working in Eclipse

  1. Eclipse Maven Plugin Not able to add dependency by Searching artifacts

You can see I was searching for springframework Java but there is no search result, in fact it was saying artifact id cannot be empty. Don’t be fool with that error this was just because we are not adding any dependency explicitly. Main problem here is that Eclipse is not able to search for dependencies when you enter some keyword in search box.Maven Dependency Search Not Working in Eclipse_第1张图片
2. Maven Settings Option in Eclipse to Enable Dependency Search from Remote Repository

In order to enable Maven dependency management feature in Eclipse, it’s not just you download and install M2Eclipse plugin but also you need to enable this options. It would be better if they are by default enabled but in Eclipse Luna it’s not. ” Download repository Index updates on startup” is the option which should be enabled otherwise you would not be able to add dependency from Eclipse GUI. Second option “Do not automatically update dependencies from remote repositories” is more to keep your start-up faster. If you enable it and you have couple of projects with lot of Maven dependencies then it will take some time before you can do anything.
Maven Dependency Search Not Working in Eclipse_第2张图片
3. Eclipse start updating Maven Index after restart

This screenshot is immediately after restarting Eclipse, you can see that at bottom right corner it showing as Updating index, which is the proof that it’s now downloading index file. If you double click there it will open the view which we have shown in next screenshot, there you can see that it downloads dependencies form Maven central remote repository.Maven Dependency Search Not Working in Eclipse_第3张图片
4. Eclipse by default download Maven dependency from Maven central remote repository

You can see that Eclipse is updating indexes and it’s doing it from Maven central repository, http://repo.maven.apache.org/maven2 . If you had configured internal nexus repository then it will download from there.Maven Dependency Search Not Working in Eclipse_第4张图片
5. Maven Dependency Search is Now working in Eclipse

Problem is fixed now, you can see that Eclipse is now able to search dependency from Maven repository. Usually after enabling those option and restarting eclipse, it will start updating index and once it finished, you would be able to search and add artificats into your pom.xml using Eclipse .Maven Dependency Search Not Working in Eclipse_第5张图片
6. Re-build Maven Index from Maven Repository view in Eclipse

In order to open Maven repository view, goto Window -> Show View -> Other -> Maven -> Maven Repositories . It will show you all kind of maven repositories e.g. local repository, Global repository, project repository and Custom repository. It is the Global repository on which Maven central library (http://repo.maven.apache.org/maven2) is configured. Just right click there and select Rebuild Index option. This will rebuild repository index for local use, and will help you to quickly add any JAR file dependency in your Maven project.Maven Dependency Search Not Working in Eclipse_第6张图片
That’s all about how do you fix this problem of Maven not able to search dependencies in Eclipse . As I said it usually happens when you are first time trying to create a Maven project in a brand new workspace and new installation of Eclipse where this options are not enabled by default. This is one time exercise, so there is very less likely hood of happening this again. Once you enable option to “Download repository Index updates on startup”, Maven will remember it and it will keep updating index every time you restart the Eclipse. Sometime this makes your Eclipse little bit slower, so you might want to disable it and then do it manually. You can also face this problem of not downloading artifact if your Eclipse is behind corporate proxy network and not able to connect to Maven central remote repository using internet. In that case just use proper proxy settings in your network connection
, see this tutorial for step by step guide of fixing Eclipse not able to connect market place problem. Another scenario on which you can face this error is You can also get this if you are using internal Maven repository, for example Nexus and the index into the proxy is messed up somehow. In that case just contact your local Maven repository admin for help.此文转载,查看原文,点击这里

你可能感兴趣的:(maven基础)