我正在使用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解决了此问题,但是我仍然不确定为什么会发生这种异常,它似乎是在网络不稳定时发生的。希望它会有所帮助。
关于java - 以编程方式从远程Maven存储库下载工件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29781791/