无法在 Eclipse 中创建 Maven 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25760961/
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
Cannot create Maven Project in eclipse
提问by Tomer
I have Eclipse Luna and Maven 3.2.3 installed on a Windows 7 machine behind a corporate firewall.
我在公司防火墙后面的 Windows 7 机器上安装了 Eclipse Luna 和 Maven 3.2.3。
Trying to create a project from an archetype results in the following error:
尝试从原型创建项目会导致以下错误:
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE
Failed to resolve version for org.apache.maven.archetypes:maven-archetype- quickstart:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-quickstart/maven-metadata.xml in local (C:\Users\xxxx.m2\repository)
Failed to resolve version for org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-quickstart/maven-metadata.xml in local (C:\Users\xxxx.m2\repository)
无法从任何配置的存储库解析原型 org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE。
无法解析工件 org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE
无法解析 org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE: 无法在本地 (C) 中找到元数据 org.apache.maven.archetypes:maven-archetype-quickstart/maven-metadata.xml :\Users\xxxx.m2\repository)
无法解析 org.apache.maven.archetypes 的版本:maven-archetype-quickstart:pom:RELEASE: 找不到元数据 org.apache.maven.archetypes:maven-archetype-quickstart/maven-metadata.xml 在本地 (C :\Users\xxxx.m2\repository)
Proxy details are configured in .m2/settings.xml
and generating a maven project from an archtype works fine in command line.
代理详细信息.m2/settings.xml
在命令行中配置并从 archtype 生成 maven 项目工作正常。
I tried to apply the solutions from herebut none worked. The remote catalog is not acessible as well. I reckon it's a problem with the network settings of Eclipse. I also looked at this bug reportto try and find some clues and couldn't really understand how to implement the workaround.
我试图从这里应用解决方案,但没有奏效。远程目录也无法访问。估计是Eclipse的网络设置有问题。我还查看了此错误报告以尝试找到一些线索,但无法真正理解如何实施解决方法。
here is my settings.xml file:
这是我的 settings.xml 文件:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>[email protected]</username>
<password>{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}</password>
</server>
<server>
<id>deployment</id>
<username>[email protected]</username>
<password>{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus-int.xxxx.xxxx.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Any ideas?
有任何想法吗?
Thanks
谢谢
Tomer
托默
回答by freesoft
Same problem here, solved.
同样的问题,解决了。
I will explain the problem and the solution, to help others.
我会解释问题和解决方案,以帮助他人。
My software is:
我的软件是:
Windows 7
Eclipse 4.4.1 (Luna SR1)
m2e 1.5.0.20140606-0033
(from eclipse repository: http://download.eclipse.org/releases/luna)
And I'm accessing internet through a proxy.
我通过代理访问互联网。
My problemwas the same:
我的问题是一样的:
- Just installed m2e, went to menu: File > New > Other > Maven > Maven project > Next > Next.
- Selected "Catalog: All catalogs" and "Filter: maven-archetype-quickstart", then clicked on the search result, then on button Next.
- Then entered "Group Id: test_gr" and "Artifact Id: test_art", then clicked on Finish button.
- Got the "Could not resolve archetype..." error.
- 刚刚安装了 m2e,转到菜单:文件 > 新建 > 其他 > Maven > Maven 项目 > 下一步 > 下一步。
- 选择“目录:所有目录”和“过滤器:maven-archetype-quickstart”,然后单击搜索结果,然后单击“下一步”按钮。
- 然后输入“Group Id: test_gr”和“Artifact Id: test_art”,然后点击完成按钮。
- 收到“无法解析原型...”错误。
After a lot of try-and-error, and reading a lot of pages, I've finally found a solution to fix it. Some important pointsof the solution:
经过大量的尝试和错误,并阅读了很多页面,我终于找到了解决方案。解决方案的一些要点:
- It uses the default (embedded) Maven installation (3.2.1/1.5.0.20140605-2032) that comes with m2e.
- So no aditional (external) Maven installation is required.
- No special m2e config is required.
- 它使用 m2e 附带的默认(嵌入式)Maven 安装 (3.2.1/1.5.0.20140605-2032)。
- 所以不需要额外的(外部)Maven 安装。
- 不需要特殊的 m2e 配置。
The solutionis:
该解决方案是:
- Open eclipse.
- Restore m2e original preferences (if you changed any of them): Click on menu: Window > Preferences > Maven > Restore defaults. Do the same for all tree items under "Maven" item: Archetypes, Discovery, Errors/Warnings, Instalation, Lifecycle Mappings, Templates, User Interface, User Settings. Click on "OK" button.
- Copy (for example to a notepad window) the path of the user settings file. To see the path, click again on menu: Window > Preferences > Maven > User Settings, and the path is at the "User settings" textbox. You will have to write the path manually, since it is not posible to copy-and-paste. After coping the path to the notepad, don't close the Preferences window.
- At the Preferences window that is already open, click on the "open file" link. Close the Preferences window, and you will see the "settings.xml" file already openned in a Eclipse editor.
- The editor will have 2 tabs at the bottom: "Design" and "Source". Click on "Source" tab. You will see all the source code (xml).
- Delete all the source code: Click on the code, press control+a, press "del".
- Copy the following code to the editor (and customize the uppercased values):
- 打开日食。
- 恢复 m2e 原始首选项(如果您更改了其中任何一个):单击菜单:窗口 > 首选项 > Maven > 恢复默认值。对“Maven”项下的所有树项执行相同操作:原型、发现、错误/警告、安装、生命周期映射、模板、用户界面、用户设置。单击“确定”按钮。
- 复制(例如到记事本窗口)用户设置文件的路径。要查看路径,请再次单击菜单:Window > Preferences > Maven > User Settings,路径位于“用户设置”文本框中。您必须手动编写路径,因为无法复制和粘贴。处理记事本的路径后,不要关闭“首选项”窗口。
- 在已打开的首选项窗口中,单击“打开文件”链接。关闭 Preferences 窗口,您将看到已在 Eclipse 编辑器中打开的“settings.xml”文件。
- 编辑器底部将有 2 个选项卡:“设计”和“来源”。单击“源”选项卡。您将看到所有源代码 (xml)。
- 删除所有源代码:点击代码,按control+a,按“del”。
- 将以下代码复制到编辑器(并自定义大写值):
<settings> <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>YOUR.PROXY.IP.OR.NAME</host> <port>YOUR PROXY PORT</port> <username>YOUR PROXY USERNAME (OR EMPTY IF NOT REQUIRED)</username> <password>YOUR PROXY PASSWORD (OR EMPTY IF NOT REQUIRED)</password> <nonProxyHosts>YOUR PROXY EXCLUSION HOST LIST (OR EMPTY)</nonProxyHosts> </proxy> </proxies> </settings>
<settings> <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>YOUR.PROXY.IP.OR.NAME</host> <port>YOUR PROXY PORT</port> <username>YOUR PROXY USERNAME (OR EMPTY IF NOT REQUIRED)</username> <password>YOUR PROXY PASSWORD (OR EMPTY IF NOT REQUIRED)</password> <nonProxyHosts>YOUR PROXY EXCLUSION HOST LIST (OR EMPTY)</nonProxyHosts> </proxy> </proxies> </settings>
- Save the file: control+s.
- Exit Eclipse: Menu File > Exit.
- Open in a Windows Explorer the path you copied (without the filename, just the path of directories).
- You will probaly see the xml file ("settings.xml") and a directoy ("repository"). Remove the directoy ("repository"): Right click > Delete > Yes.
- Start Eclipse.
- Now you will be able to create a maven project: File > New > Other > Maven > Maven project > Next > Next, select "Catalog: All catalogs" and "Filter: maven-archetype-quickstart", click on the search result, then on button Next, enter "Group Id: test_gr" and "Artifact Id: test_art", click on Finish button.
- 保存文件:control+s。
- 退出 Eclipse:菜单文件 > 退出。
- 在 Windows 资源管理器中打开您复制的路径(没有文件名,只有目录路径)。
- 您可能会看到 xml 文件(“settings.xml”)和一个目录(“repository”)。删除目录(“存储库”):右键单击 > 删除 > 是。
- 启动日食。
- 现在你就可以创建一个maven项目了:文件>新建>其他>Maven>Maven项目>下一步>下一步,选择“目录:所有目录”和“过滤器:maven-archetype-quickstart”,点击搜索结果,然后在按钮上下一步,输入“组 ID:test_gr”和“工件 ID:test_art”,单击“完成”按钮。
Finally, I would like to give a suggestionto m2e developers, to make config easier. After installing m2e from the internet (from a repository), m2e should check if Eclipse is using a proxy (Preferences > General > Network Connections). If Eclipse is using a proxy, the m2e should show a dialog to the user:
最后,我想给m2e 开发人员一个建议,使配置更容易。从互联网(从存储库)安装 m2e 后,m2e 应该检查 Eclipse 是否正在使用代理(首选项 > 常规 > 网络连接)。如果 Eclipse 使用代理,则 m2e 应该向用户显示一个对话框:
m2e has detected that Eclipse is using a proxy to access to the internet.
Would you like me to create a User settings file (settings.xml) for the embedded
Maven software?
[ Yes ] [ No ]
If the user clicks on Yes, then m2e should create automatically the "settings.xml" file by copying proxy values from Eclipse preferences.
如果用户单击 Yes,则 m2e 应通过从 Eclipse 首选项复制代理值来自动创建“settings.xml”文件。
回答by amanteaux
For me the solution was a bit simpler, I just had to clean the repository : .m2/repository/org/apache/maven/archetypes
对我来说,解决方案有点简单,我只需要清理存储库:.m2/repository/org/apache/maven/archetypes
回答by LottaLava
Just delete the ${user.home}/.m2/repository/org/apache/maven/archetypes to refresh all files needed, it worked fine to me!
只需删除 ${user.home}/.m2/repository/org/apache/maven/archetypes 即可刷新所需的所有文件,对我来说效果很好!
回答by OO7
In my case following solution worked.
在我的情况下,以下解决方案有效。
- Delete RELEASEdirectory & resolver-status.propertiesfile in your local Maven repository under directory .m2/../maven-archetype-quickstart.
- Create Maven project in Eclipse or STS (Spring Tool Suite). It will automatically download quickstart archetype & work as expected.
- 删除.m2/../maven-archetype-quickstart 目录下本地 Maven 存储库中的RELEASE目录和resolver-status.properties文件。
- 在 Eclipse 或 STS(Spring Tool Suite)中创建 Maven 项目。它将自动下载快速入门原型并按预期工作。
I hope this may help someone.
我希望这可以帮助某人。
回答by u4840403
I GOT THIS problem too, and I solved it finally, this is the solution:
我也遇到了这个问题,我终于解决了,这是解决方案:
go to windows-->preference-->maven-->user settings
转到windows-->首选项-->maven-->用户设置
Change the settings.xml
path to a valid path.
将settings.xml
路径更改为有效路径。
The path maybe not under .m2 directory (in your home directory)..
路径可能不在 .m2 目录下(在您的主目录中)。
回答by Thomas Okonkwo
It's actually easy and straight forward.
这实际上很简单直接。
just navigate to your .m2 folder.
只需导航到您的 .m2 文件夹。
.m2/repository/org/apache/maven
.m2/repository/org/apache/maven
inside this maven folder, you will see a folder called Archetypes... delete this folder and the problem is solved.
在这个 maven 文件夹中,你会看到一个名为 Archetypes 的文件夹......删除这个文件夹,问题就解决了。
but if you don't feel like deleting the whole folder, you can navigate into the archetype folder and delete all the archetype you want there. The reason why it keeps failing is because, the archetype you are trying to create is trying to tell you that she already exists in that folder, hence move away...
但是如果你不想删除整个文件夹,你可以导航到原型文件夹并删除你想要的所有原型。它不断失败的原因是,您尝试创建的原型试图告诉您她已经存在于该文件夹中,因此请移开...
summarily, deleting the archetype folder in the .m2 folder is the easiest solution.
总之,删除 .m2 文件夹中的原型文件夹是最简单的解决方案。
回答by bibangamba
I had the same error show up while creating the project but I wasn't behind a proxy and hence the above solutions did not work for me.
我在创建项目时出现了同样的错误,但我没有使用代理,因此上述解决方案对我不起作用。
I found this forum. It suggested to:
我找到了这个论坛。它建议:
- Delete or Rename .m2 directory from your HOME directory
- 从您的 HOME 目录中删除或重命名 .m2 目录
In Windows - C:\Users\<username>\Windows
In Windows - C:\Users\<username>\Windows
OR
或者
In Linux - /home/<username>
- restart the Eclipse / STS spring tool suite (which am using)
- 重新启动 Eclipse / STS spring 工具套件(正在使用)
It worked!
有效!
回答by gnattyp
I am using Spring STS 3.8.3. I had a similar problem. I fixed it by using information from this threadAnd also by fixing some maven settings. click Spring Tool Suite -> Preferences -> Maven and uncheck the box that says "Do not automatically update dependencies from remote depositories" Also I checked the boxes that say "Download Artifact Sources" and "download Artifact javadoc".
我正在使用 Spring STS 3.8.3。我有一个类似的问题。我通过使用来自该线程的信息以及修复一些 maven 设置来修复它。单击 Spring Tool Suite -> 首选项 -> Maven 并取消选中“不自动更新远程存储库的依赖项”框我还选中了“下载工件源”和“下载工件 javadoc”框。
回答by Ostati
If you're behind a proxy, the very first thing to do is, add settings.xml
with proxy configs under C:\Users\{username}\.m2
folder, and replicate same proxy configs under Window > Preferences > Network Connections
(you may need to prefix your user name with domain eg. DOMAIN\username
):
如果您在代理后面,首先要做的是,settings.xml
在C:\Users\{username}\.m2
文件夹下添加代理配置,并在下复制相同的代理配置Window > Preferences > Network Connections
(您可能需要在您的用户名前加上域,例如。DOMAIN\username
):
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>webproxy.net</host>
<port>8080</port>
<username>username</username>
<password>password</password>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
<proxy>
<active>true</active>
<protocol>https</protocol>
<host>webproxy.net</host>
<port>8080</port>
<username>username</username>
<password>password</password>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
Delete C:\Users\{username}\.m2\repository
folder as well.
也删除C:\Users\{username}\.m2\repository
文件夹。
回答by Vinod Joshi
It worked for = I just removed "archetypes" folder from below location
它适用于 = 我刚刚从下面的位置删除了“原型”文件夹
C:\Users\Lenovo.m2\repository\org\apache\maven
C:\Users\Lenovo.m2\repository\org\apache\maven
But you may change following for experiment - download latest binary zip of Maven, add to you C:\ drive and change following....
但是您可以更改以下进行实验 - 下载最新的 Maven 二进制 zip,添加到您的 C:\ 驱动器并更改以下....
Change Proxy
更改代理
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>10.23.73.253</host>
<port>8080</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>