// need to backup (and later restore) the current class loader, because the Maven/Plexus does some classloader
// magic which then results in CNFE in RestEasy client
// run the Maven build which will create the kjar. The kjar is then either installed or deployed to local and
// remote repo
ClassLoader classLoaderBak = Thread.currentThread().getContextClassLoader();
MavenCli cli = new MavenCli();
String[] mvnArgs;
if (LOCAL_SERVER) {
// just install into local repository when running the local server. Deploying to remote repo will fail
// if the repo does not exists.
mvnArgs = new String[]{"-B", "clean", "install"};
} else {
mvnArgs = new String[]{"-B", "clean", "deploy"};
}
int mvnRunResult = cli.doMain(mvnArgs, basedir, System.out, System.out);
if (mvnRunResult != 0) {
throw new RuntimeException("Error while building Maven project from basedir " + basedir +
". Return code=" + mvnRunResult);
}
Thread.currentThread().setContextClassLoader(classLoaderBak);