Dynamic loading of Maven artifacts at runtime - maven

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.

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.

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

Related

Not able to load multiple ( 200+ )external jars from my /lib folder into my Sprirngboot maven/gradle project

I will need to load 200+ external jars( form my local harddisc) into Springboot REST project. Tried many approaches but none of them are working, Much appreciated if someone has solution.
Note: Please do not suggest mvn install or system scope as i need to construct artifacts for 200+ jar's which i dont like to do manually
Tried google add jar's plugin too its just copying the ${basedir}/lib/*.jars into my Maven target folder but not found in runtime.
If your company works with Maven, it should run a Maven repository server like Nexus or Artifactory. When someone builds artifacts, they should be deployed to the Nexus/Artifactory and can then easily be read from there.
If this is not the case and you do not have a Nexus/Artifactory, you need to either install the JARs in your local repository (mvn install:install-file) or you need structure them in the standard repository layout (like log4j/log4j/1.2.17/log4j-1.2.17.jar) and import this directory as repository.
In any case, this will be a lot of manual work (as you already said).

How to use "maven-publish" gradle plugin for bintray jfrog repo?

I want to publish my maven artifacts to standard maven repositories. For that the first example I chose is bintray Jfrog. Unfortunately this didn’t go well.
I had to add two hacks.
Remove existing artifacts if pushing same version again
Delete some corrupted versions after maven publish
The entire code can be found at https://github.com/pPanda-beta/cassandra-java-driver-reactive-mapper/blob/4b1395db443facb188ed4aee120c6db7864908b7/cassandra-java-driver-reactive-mapper-reactor-core/build.gradle#L93-L122
The uploaded artifacts are at https://bintray.com/ppanda-beta/maven/cassandra-java-driver-reactive-mapper-reactor-core
Why maven-publish?
The main objective here is to keep maven artifactories as a standard specification not specific to any provider. I want to represent an repo as { url, username, password } . The way of publishing should not change based on the repo provider.
PLEASE DO NOT SUGGEST ANY OTHER PLUGIN THAN 'maven-publish', I DONT WANT TO USE com.jfrog.bintray or com.jfrog.artifactory PLUGINS WHICH ARE VERY SPECIFIC TO BINTRAY JFROG.
What is wrong with current solution?
It is hacky. It is no better than jfrog gradle plugins. The solution is already using custom hacks which are not valid for other maven repos.
Why not switch to Jfrog altogether ?
The future of those artifacts is to reside in a more popular and standard maven repo like : maven central, github maven repo, ...etc. So anyway I'm gonna leave jFrog in near future. Till that time comes, I want to standardise the gradle script to work with any maven repo. This is very similar to docker container registry. Whether it is global docker hub or redhat cr or google cr, we use the same docker clients.

Is it possible to make a maven-repository with a static-website?

Stupide idea but ... is it possible to create a maven repository from a static website?
if I mannualy put pom and jar file on a website with a path similar to the one on any maven repository, then I reference the website as a maven repository from which I try to import dependency, will it work ?
I need it in order to store my snapshot version without publishing them. I don't care of security but I have 0 budget

Reg upload to artifactory

We maintain an artifactory within our intranet which is used by the development team.
When ever any new dependency is added to any project , we upload the new jars into artifactory.
This is currently a tedious process and we are trying to find if there is any simple way out.
The current process is - if a project defines a new dependency , we need to connect to internet and build the project using gradle so that we get to know what are the new dependencies ( we in fact track the logs what are the dependant and transitive dependant jars which are getting downloaded fresh )
Then we create a zip of these new jars alone and upload to artifactory. This is time consuming and error prone as well
Is there any better way to achieve this ? When i build using gradle connecting to internet , is it possible to publish the new dependencies as well to maven local repo or to some new folder so that we can zip that folder alone and upload to artifactory ?
Kindly revert if anybody has a simple solution for the above problem.
This is a maven answer but the same will apply to gradle.
You should be able to define a virtual repository in your artifactory, which is a combination of the local (artifactory hosted) and the maven central repo (internet hosted).
Your maven/gardle users will configure the virtual repository (not the internet) in their settings.xml, then when a dependency is loaded maven will look in repostories in the following order:
1) local user repo at ~/.m2/repo
2) artifactory local repository
3) maven central
Each time a new artifact is loaded from 3 (no one has ever asked for it before) it will be added to 2 and 1, so the next user who calls for that dependency will only ever go as far as 2.
See https://www.jfrog.com/confluence/display/RTF/Virtual+Repositories

Jars in Maven Central needs to go into Nexus OSS?

I need to set up my own maven repository, since some open sourced libraries are not in Maven Central. I want to use Nexus OSS, and then I can upload the libraries I need to Nexus OSS.
My question is, do I also need to upload those libraries that are originally in Maven Central and I can directly use in POM to Nexus OSS?
Nexus is a proxy for global repositories. You can define in Nexus configuration what repositories are you going to use. You do not need to upload libraries that are accessible from configured global repositories.
You can also host your own repository for your local libraries. Everything is configurable.
When you configure your Nexus you need to just connect to it trough maven config and all actions are done behind the scene. Don't worry about it.
All libraries that are needed to compile your project, firstly are downloaded to your Nexus and then from Nexus to your local repo.
For example this is the easiest way to configure Nexus with your maven:
Nexus - maven - Configuration
Not at all: In your local $userprofile/.m2/settings.xml file (as well as in every pom.xml, altough is not a good practice) you can define as many repositories as you want. And so, you will be able to reference artifacts published to different repositories.

Resources