在运行时,我的应用程序想要动态添加功能。我们希望能够从 Maven 存储库下载 Artifact ,将它们添加到类路径中,然后在不重启应用服务器的情况下使用它们。可能吗?
我遇到了 Eclipse Aether,它提供了对 Maven 存储库的编程访问。现在缺少的部分是动态类路径。
最佳答案
Sonatype 的 Aether 就是您所需要的。尝试使用 jcabi-aether ,它是 Aether 的包装器:
File repo = this.session.getLocalRepository().getBasedir();
Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
JavaScopes.RUNTIME
);
您只需要知道一个远程 Maven 存储库列表、一个本地存储库位置和开始使用的 Artifact 的 Maven 坐标。
关于maven - 在运行时动态加载 Maven Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13055968/