gpt4 book ai didi

java - 使用 java 和 aether 从远程存储库下载 Artifactory

转载 作者:行者123 更新时间:2023-12-02 04:19:14 26 4
gpt4 key购买 nike

我尝试使用 java 和 aethor 库连接到远程存储库,通过代码手动下载 Artifactory ,即 jar/zip/war。但我发现文档不是很有帮助,有人有什么想法吗?

这就是我所拥有的

public static void main( String[] args ) throws Exception {
DefaultServiceLocator locator = new DefaultServiceLocator();
locator.addService( RepositoryConnectorFactory.class, AsyncRepositoryConnectorFactory.class );
locator.addService( RepositoryConnectorFactory.class, WagonRepositoryConnectorFactory.class );
locator.addService( VersionResolver.class, DefaultVersionResolver.class );
locator.addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
locator.addService( ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class );
locator.setServices( WagonProvider.class, new WagonProvider() {
public Wagon lookup( String roleHint ) throws Exception {
if( "http".equals( roleHint ) ) {
return new LightweightHttpWagon();
}
return null;
}

public void release( Wagon wagon ) {}
} );

RepositorySystem system = locator.getService( RepositorySystem.class );

MavenRepositorySystemSession session = new MavenRepositorySystemSession();

LocalRepository localRepo = new LocalRepository( "target/local-repo" );
session.setLocalRepositoryManager( system.newLocalRepositoryManager( localRepo ) );

Artifact artifact = new DefaultArtifact( "junit:junit:4.8.2" );

// RemoteRepository repo = new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
Authentication authentication = new Authentication( "atestuser", "apassword" );
RemoteRepository repo = new RemoteRepository( ).setUrl( "https://somerepository/repo/" ).setAuthentication( authentication );


RepositoryConnector connector = new AsyncRepositoryConnectorFactory().newInstance( session, repo );

ArtifactDownload artDown = new ArtifactDownload( artifact, null, new File("C:\\test\\junit.jar"), null );
connector.get( Arrays.asList( artDown ), null );

connector.close();

ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( artifact );
artifactRequest.addRepository( repo );

ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest );

artifact = artifactResult.getArtifact();

System.out.println( artifact + " resolved to " + artifact.getFile() );
}

最佳答案

我还使用 eclipse aether 下载 Artifactory 。我发现从 eclipse aether 开始比旧的 sonatype aether 有点难,但这是我作为开源项目的一部分创建的一个小示例项目:MavenPP

还有一个很好的演示项目,展示了 eclipse aether 的许多功能:aether-demo

希望这有帮助;)

关于java - 使用 java 和 aether 从远程存储库下载 Artifactory ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32974693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com