How to Update Maven Repository in Eclipse

How to update maven repository in Eclipse?

You can right-click on your project then Maven > Update Project..., then select Force Update of Snapshots/Releases checkbox then click OK.

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).

So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.

As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:

Sample Image

If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.

Sample Image

What exactly does Maven Update Project do in Eclipse?

Does Update project run any Maven plugin and, if so, which ones and with which default settings?

During the update project, m2eclipse uses maven-core build project object model. Specifically, maven model builder is used to build project model. In other words, it leads to dependency resolution, error and warning notification. For more information about the result, you can check org.apache.maven.project.ProjectBuildingResult

I don't think that it results in running of plugins. I took a cursory look and phase 2 while doing update is not enabled which does plugin processing.

Are there effects which are not a result of a Maven plugin, but are internal to Eclipse?

Yes. See the end section of the answer.

What are the modifications on the project structure? For instance, are Maven dependencies copied locally?

If by locally you mean, in eclipse workspace then no. Maven Dependencies shows reference to the local repository which is usually /.m2/repository. The Repository is also resolved based on the setting of Eclipse menu "Windows->Preference->User Settings".

For further information, you can begin from the following source code (one of the methods invoked when you do update project in eclipse),

public IStatus runInWorkspace(IProgressMonitor monitor) {
...... Unimportant stuff

MavenUpdateRequest request = new MavenUpdateRequest(projects, offline,forceUpdateDependencies);
Map<String, IStatus> updateStatus = configurationManager.updateProjectConfiguration(request, updateConfiguration,
cleanProjects, refreshFromLocal, monitor);

...... Unimportant stuff

}

Summary of different tasks performed (not exhaustive)

  1. Project is refreshed with respect to file system. This is similar to calling refresh on the java project in eclipse.
  2. Check if one of the dependencies have been added in the workspace. You must have noticed under maven dependencies local project folder. Junit and other stuff will pick changes using this feature.
  3. Build maven project model using maven-core libraries.
  4. Lifecycle mapping refresh - M2Eclipse tries to map some of the plugin lifecycles to eclipse actions. For more information, check
  5. Finally, Builds Project using Eclipse build mechanism

Additionally, it also does some stuff with parent pom presence in the workspace which is not very important in this context.

Update Project configuration is majorly related to

  1. Adding Maven nature (org.eclipse.m2e.core.maven2Nature in .project file) - not important in your context. See this.
  2. Setting default charset for your project based on project.build.sourceEncoding maven property.
  3. Eclipse - plugin lifecycle processing. Point 3 above.

Maven Dependencies Eclipse

This depends on how you have integrated Maven in Eclipse:

  • No Eclipse integration: run mvn eclipse:eclipse on command line to refresh the project definition.
  • M2Eclipse or m2e: Update the POM file (select, press F5), then right-click the project, Maven > Update Dependencies

This should fix it.

Missing Maven dependencies in Eclipse project

Problem solved!

I don't know what exactly solved it, but I did 4 things in Eclipse:

  • Window->Preferences: Maven->Installations: Global settings -> open file and hardcoded localRepository
  • Project->Clean
  • right click on project: Maven->Update dependencies
  • right click on project: Maven->Update project configuration

I guess it was the Update dependencies since right after first two there were no change.

Maven not downloading dependencies in Eclipse

Solution 1:

Set correct proxy:

<proxy>
<id>optional</id>
<active>false</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>172.27.171.91</host>
<port>8080</port>
</proxy>

Solution2 :

just delete

lastupdated extension files from folder

and try updating maven.

[Most of the times this solution will work]

Add Maven repositories for a project in Eclipse?

You can include it in your pom.xml. Just add the repositories information inside the <project> tag

<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
</repository>
</repositories>


Related Topics



Leave a reply



Submit