gpt4 book ai didi

java - Maven,拒绝访问 : http://repo1. maven.org/maven2

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:31:06 25 4
gpt4 key购买 nike

我刚刚下载了最新版本的 Maven。

当我想跑的时候

mvn archetype:generate

我收到错误信息

[WARNING] Error reading archetype catalog http://repo1.maven.org/maven2 org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://repo1.maven.org/maven2 , ReasonPhrase:Denied Access. at org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:928) at org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:116) at org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88) at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61) at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.downloadCatalog(RemoteCatalogArchetypeDataSource.java:119) at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.getArchetypeCatalog(RemoteCatalogArchetypeDataSource.java:87) at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(DefaultArchetypeManager.java:216) at org.apache.maven.archetype.DefaultArchetypeManager.getRemoteCatalog(DefaultArchetypeManager.java:205) at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.getArchetypesByCatalog(DefaultArchetypeSelector.java:200) at org.apache.maven.archetype.ui.generation.DefaultArchetypeSelector.selectArchetype(DefaultArchetypeSelector.java:71) at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute(CreateProjectFromArchetypeMojo.java:197) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) [WARNING] No archetype found in remote catalog. Defaulting to internal catalog [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)

我没有代理,互联网工作正常。防火墙已关闭。如何解决这个问题?

感谢您的帮助。

如果我们查看类org.apache.maven.wagon.shared.http4.AbstractHttpClientWagon方法 fillInputData( InputData inputData ) 我们可以看到:

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

So problem caused because we have HTTP 403 Forbidden error in response.但是我不知道该怎么办...


所以现在我们知道我们收到了 FORBIDDEN 错误,因为我们在 HTTP 请求中没有 User-Agent。 Thanx to Patouche

最佳答案

好像是在 http://repo1.maven.org/maven2 上浏览目录已关闭。我不得不求助于自己获取原型(prototype)目录。我这样做了:

mvn archetype:generate -DarchetypeCatalog=http://search.maven.org/remotecontent?filepath=archetype-catalog.xml

或者,我想您可以从该链接下载 archetype-catalog.xml 文件并将其放置在您的 .m2 目录中,如评论中所述:

http://jira.codehaus.org/browse/ARCHETYPE-202?focusedCommentId=182771&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-182771

关于java - Maven,拒绝访问 : http://repo1. maven.org/maven2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com