简体   繁体   English

以编程方式从远程Maven存储库下载工件

[英]Downloading artifacts from remote maven repo programmatically

I am using Aether utility library to manage deppendencies. 我正在使用Aether实用程序库来管理依赖性。 When I try to download the transitive dependencies for a maven artifact I get a 当我尝试下载Maven工件的传递依赖时,我得到了一个

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 我在这里使用以太示例中几乎相同的代码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.
   */

public class ResolveTransitiveDependencies { 公共类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() );
    }
}

} }

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. 我通过删除本地存储库中的工件jar解决了此问题,但是我仍然不确定为什么会发生这种异常,它似乎是在网络不稳定时发生的。 Hope it will help. 希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM