Dynamic loading of Maven artifacts at runtime

731 Views Asked by At

At runtime my app would like to add functionality dynamically. We'd like to be able to download artifacts from a Maven repo, add them to the classpath, and use them without doing an app server restart. Possible?

I have come across Eclipse Aether, which give programmatic access to Maven repos. Now the missing piece is the dynamic classpath.

2

There are 2 best solutions below

0
On

If you're not against using a commercial product, one option is LiveRebel

3
On

Aether from Sonatype is what you need. Try to use jcabi-aether, which is a wrapper around 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
);

All you need to know is a list of remote Maven repositories, a local repo location, and Maven coordinates of the artifact to start with.