以编程方式从远程maven repo下载工件

时间:2015-04-21 19:49:30

标签: java ioexception aether

我正在使用Aether实用程序库来管理deppendencies。当我尝试下载maven工件的传递依赖项时,我得到了一个

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

错误。我在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 {

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

}

1 个答案:

答案 0 :(得分:4)

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

相关问题