问题
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.
*/
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:
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.
来源:https://stackoverflow.com/questions/29781791/downloading-artifacts-from-remote-maven-repo-programmatically