问题描述
我刚刚下载了最新版本的 Maven.
I have just downloaded last version of Maven.
当我试图跑步时
mvn 原型:生成
我收到错误信息
[警告] 读取原型目录时出错http://repo1.maven.org/maven2org.apache.maven.wagon.authorization.AuthorizationException:访问拒绝:http://repo1.maven.org/maven2,ReasonPhrase:拒绝访问.在org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:928)在org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:116)在 org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88)在 org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61) 在org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.downloadCatalog(RemoteCatalogArchetypeDataSource.java:119)在org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.getArchetypeCatalog(RemoteCatalogArchetypeDataSource.java:87)在org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(DefaultArchetypeManager.java:216)在org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(DefaultArchetypeManager.java:205)在org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.getArchetypesByCatalog(DefaultArchetypeSelector.java:200)在org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.selectArchetype(DefaultArchetypeSelector.java:71)在org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:197)在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)在org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)在 org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 在org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 在org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 在sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) atsun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) atjava.lang.reflect.Method.invoke(Unknown Source) atorg.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)[警告] 在远程目录中找不到原型.默认为内部目录 [INFO] 未定义原型.使用 maven-archetype-quickstart(org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
我没有代理,互联网工作正常.防火墙已关闭.如何解决这个问题?
I have not Proxy and internet works fine. Firewall is turned off. How to solve this problem ?
感谢您的帮助.
如果我们查看类 org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon方法 fillInputData( InputData inputData ) 我们可以看到这个:
If we look to the class org.apache.maven.wagon.shared.http4.AbstractHttpClientWagonmethod fillInputData( InputData inputData ) we can see this:
public void fillInputData( InputData inputData )
throws TransferFailedException, ResourceDoesNotExistException,AuthorizationException
{
....
HttpResponse response;
....
statusCode = response.getStatusLine().getStatusCode();
....
switch ( statusCode )
{
case HttpStatus.SC_OK:
break;
case HttpStatus.SC_NOT_MODIFIED:
// return, leaving last modified set to original value so getIfNewer should return unmodified
return;
case SC_NULL:
{
TransferFailedException e =
new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
fireTransferError( resource, e, TransferEvent.REQUEST_GET );
throw e;
}
case HttpStatus.SC_FORBIDDEN: // <---------THIS
fireSessionConnectionRefused();
throw new AuthorizationException( "Access denied to: " + url + reasonPhrase);
....
}
...
}
所以问题是因为我们有 HTTP 403 Forbidden 错误响应.一>但我不知道该怎么办...
So problem caused because we have HTTP 403 Forbidden error in response.But i dont know what to do...
所以现在我们知道我们收到 FORBIDDEN 错误,因为我们在 HTTP 请求中没有 User-Agent.感谢Patouche
So now we know that we are getting FORBIDDEN error because we have not User-Agent in HTTP request. Thanx to Patouche
推荐答案
似乎在 http://repo1.maven 上浏览目录.org/maven2 已关闭.我不得不求助于自己获取原型目录.我是这样做的:
It seems as though directory browsing on http://repo1.maven.org/maven2 has been switched off. I had to resort to getting the archetype catalog myself. I did this:
mvn archetype:generate -DarchetypeCatalog=http://search.maven.org/remotecontent?filepath=archetype-catalog.xml
或者,我想您可以从该链接下载 archetype-catalog.xml 文件并将其放置在您的 .m2 目录中,如本评论所述:
Alternatively I guess you could just download the archetype-catalog.xml file from that link and place it in your .m2 directory as mentioned in this comment:
这篇关于Maven,拒绝访问:http://repo1.maven.org/maven2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!