簡體   English   中英

以編程方式從遠程Maven存儲庫下載工件

[英]Downloading artifacts from remote maven repo programmatically

我正在使用Aether實用程序庫來管理依賴性。 當我嘗試下載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.
   */

公共類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解決了此問題,但是我仍然不確定為什么會發生這種異常,它似乎是在網絡不穩定時發生的。 希望它會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM