以编程方式从远程Maven存储库下载工件 [英] Downloading artifacts from remote maven repo programmatically

查看:158
本文介绍了以编程方式从远程Maven存储库下载工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Aether实用程序库来管理依赖性.当我尝试下载Maven工件的传递依赖时,我得到了

I am using Aether utility library to manage deppendencies. When I try to download the transitive dependencies for a maven artifact I get a

java.io.IOException: Invalid Content-Range header for partial download

错误.我在这里的以太示例中使用几乎相同的代码

error. I am using almost the same code from the aether example here https://github.com/eclipse/aether-demo/blob/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java

  /**
  * Resolves the transitive (compile) dependencies of an artifact.
   */

公共类ResolveTransitiveDependencies {

public class ResolveTransitiveDependencies {

public static void main( String[] args )
    throws Exception
{
    System.out.println( "------------------------------------------------------------" );
    System.out.println( ResolveTransitiveDependencies.class.getSimpleName() );

    RepositorySystem system = Booter.newRepositorySystem();

    RepositorySystemSession session = Booter.newRepositorySystemSession( system );

    Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );

    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
    collectRequest.setRepositories( Booter.newRepositories( system, session ) );

    DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter );

    List<ArtifactResult> artifactResults =
        system.resolveDependencies( session, dependencyRequest ).getArtifactResults();

    for ( ArtifactResult artifactResult : artifactResults )
    {
        System.out.println( artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile() );
    }
}

}

推荐答案

我通过删除本地存储库中的工件jar解决了此问题,但是我仍然不确定为什么会发生这种异常,它似乎是在网络处于不稳定.希望它会有所帮助.

I resolved this problem by removing the artifact jars in local repository, however I'm still not sure why this exception happens, it seems to occur when the network is not stable. Hope it will help.

这篇关于以编程方式从远程Maven存储库下载工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆