I am adding M2_REPO variable in eclipse using Window --> Preferences --> Java --> Build Path --> Classpath Variables --> New -->
and then providing name as M2_REPO and selecting maven repository folder, then I see this variable getting added in the Classpath variables list. Then I click OK button.
After that, if again I see the above Classpath variables , then i don't find the M2_REPO variable there, due to which I am getting Unbound classpath variable: M2_REPO/....jar
error in my project.
Can someone please help.
Check for settings.xml in
Window --> Preferences --> Maven ---> User Settings
If not, set it there and change localRepository path in settings tag inside settings.xml. Normally you will find settings.xml in .m2 folder under the user folder (for eg. C:\\Documents and Settings\\userName.m2).
I think that you're doing it wrong. If you're using Eclipse (a later version, something like Juno), you shouldn't deal with the M2_REPO
classpath variable at all. You should adjust your Maven settings by going to Window -> Preferences -> Maven -> User Settings. The M2_REPO
is derived from those settings and you must not override it manually.
My M2_REPO variable kept disappearing as well, the hint for me was here:
I'm running Spring Tool Suite 3.6.2 (which is based off Eclipse Luna).
In my workspace there's a file workspace-sts-3.6.2.RELEASE\\.metadata\\.plugins\\org.eclipse.core.runtime\\.settings\\org.eclipse.jdt.core.prefs
Add the following line:
org.eclipse.jdt.core.classpathVariable.M2_REPO=<your repo location>
Restart Eclipse/STS, and the M2_REPO classpath variable should be there again.
Edit: It happened to me again. :'(
The step above didn't work the second time, but doing
mvn -Declipse.workspace="(path to workspace)" eclipse:configure-workspace
added the M2_REPO variable again.
In my case it turned out that I had a problem with maven. Paste
mvn --version
in your command line. Does it show maven version correctly? If not, then check your system variables : M2_HOME, M2. If they are not set -> set it to the correct maven directory and restart Eclipse. Everything should be fine, M2_REPO will be added automatically.
If they exist and they are set to the correct maven directory, check your JAVA_HOME and PATH variables as different maven versions require different java version. If it's not correct version of java -> set it to the correct one.
This solved my problem for good:).
Possible cause of this problem is the m2e
maven plugin. If using this plugin, I would suggest to remove it and use mvn eclipse:eclipse
instead.
How to remove m2e
, click here for help :
m2e
from plugin
folder in eclipse installation location The direct form to resolve it:
mvn -Declipse.workspace="/path/to/workspace" eclipse:configure-workspace
Description of command in the documentation:
Configures The following Eclipse Workspace features
Adds the classpath variable MAVEN_REPO to Eclipse. Optionally load Eclipse code style file via a URL.
-Declipse.workspace is a required parameter Directory location of the Eclipse workspace. User property is: eclipse.workspace.
Ref: http://maven.apache.org/plugins/maven-eclipse-plugin/configure-workspace-mojo.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.