在 Eclipse 中添加 M2_REPO 变量的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13679810/
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-19 19:32:41  来源:igfitidea点击:

Issue in adding M2_REPO variable in eclipse

javaeclipsemaven

提问by Anand

I am adding M2_REPO variable in eclipse using Window --> Preferences --> Java --> Build Path --> Classpath Variables --> New -->and then providing name as M2_REPOand selecting maven repository folder, then I see this variable getting added in the Classpath variableslist. Then I click OK button.

我在 eclipse 中使用添加 M2_REPO 变量,Window --> Preferences --> Java --> Build Path --> Classpath Variables --> New -->然后提供名称为M2_REPO并选择 maven 存储库文件夹,然后我看到这个变量被添加到类路径变量列表中。然后我点击确定按钮。

After that, if again I see the above Classpath variables, then i don't find the M2_REPOvariable there, due to which I am getting Unbound classpath variable: M2_REPO/....jarerror in my project.

之后,如果我再次看到上面的Classpath 变量,那么我在那里找不到M2_REPO变量,因此我Unbound classpath variable: M2_REPO/....jar在我的项目中遇到错误。

Can someone please help.

有人可以帮忙吗。

回答by Vishal Pahuja

Check for settings.xml in

检查 settings.xml 中的

Window --> Preferences --> Maven ---> User Settings

窗口 --> 首选项 --> Maven ---> 用户设置

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).

如果没有,请将其设置在那里并在 settings.xml 中的设置标记中更改 localRepository 路径。通常,您会在用户文件夹下的 .m2 文件夹中找到 settings.xml(例如 C:\Documents and Settings\userName.m2)。

回答by Isaac

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_REPOclasspath variable at all. You should adjust your Maven settings by going to Window -> Preferences -> Maven -> User Settings. The M2_REPOis derived from those settings and you must not override it manually.

我认为你做错了。如果您使用的是 Eclipse(更高版本,例如 Juno),则根本不应该处理M2_REPO类路径变量。您应该通过转到 Window -> Preferences -> Maven -> User Settings 来调整您的 Maven 设置。该M2_REPO从这些设置导出,你不能手动覆盖它。

回答by Fodder

My M2_REPO variable kept disappearing as well, the hint for me was here:

我的 M2_REPO 变量也一直消失,给我的提示在这里:

http://maven.40175.n5.nabble.com/Eclipse-Plugin-how-to-remove-M2-REPO-classpath-variable-re-post-td3375082.html

http://maven.40175.n5.nabble.com/Eclipse-Plugin-how-to-remove-M2-REPO-classpath-variable-re-post-td3375082.html

I'm running Spring Tool Suite 3.6.2 (which is based off Eclipse Luna).

我正在运行 Spring Tool Suite 3.6.2(基于 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

在我的工作区中有一个文件 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.

重新启动 Eclipse/STS,M2_REPO 类路径变量应该会再次出现。

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.

再次添加了 M2_REPO 变量。

回答by user2455862

In my case it turned out that I had a problem with maven. Paste

就我而言,结果证明我在使用 maven 时遇到了问题。粘贴

mvn --version

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.

在您的命令行中。它是否正确显示了 Maven 版本?如果没有,请检查您的系统变量:M2_HOME、M2。如果未设置 -> 将其设置为正确的 maven 目录并重新启动 Eclipse。一切都应该没问题,M2_REPO 将自动添加。

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.

如果它们存在并且它们被设置为正确的 maven 目录,请检查您的 JAVA_HOME 和 PATH 变量,因为不同的 maven 版本需要不同的 java 版本。如果它不是正确的 java 版本 -> 将其设置为正确的版本。

This solved my problem for good:).

这彻底解决了我的问题:)。

回答by Barun

Possible cause of this problem is the m2emaven plugin. If using this plugin, I would suggest to remove it and use mvn eclipse:eclipseinstead.

此问题的可能原因是m2emaven 插件。如果使用此插件,我建议将其删除并使用mvn eclipse:eclipse

How to remove m2e, click here for help:

如何删除m2e,点击这里获取帮助

  1. Uninstall from Eclipse menu: About Eclipse -> Installation Details -> Installed Software
  2. Delete plugin files and folder with name m2efrom pluginfolder in eclipse installation location
  1. 从 Eclipse 菜单卸载:About Eclipse -> Installation Details -> Installed Software
  2. m2eplugineclipse安装位置的文件夹中删除插件文件和同名文件夹

回答by Leandro Souza

The direct form to resolve it:

解决它的直接形式:

mvn -Declipse.workspace="/path/to/workspace" eclipse:configure-workspace

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.

配置以下 Eclipse Workspace 功能

将类路径变量 MAVEN_REPO 添加到 Eclipse。可选择通过 URL 加载 Eclipse 代码样式文件。

-Declipse.workspace is a required parameter Directory location of the Eclipse workspace. User property is: eclipse.workspace.

-Declipse.workspace 是必需参数 Eclipse 工作区的目录位置。用户属性是:eclipse.workspace。

Ref: http://maven.apache.org/plugins/maven-eclipse-plugin/configure-workspace-mojo.html

参考:http: //maven.apache.org/plugins/maven-eclipse-plugin/configure-workspace-mojo.html