oehme commented on code in PR #784: URL: https://github.com/apache/maven-mvnd/pull/784#discussion_r1097293553
########## common/src/main/java/org/mvndaemon/mvnd/common/MavenDaemon.java: ########## @@ -18,67 +18,39 @@ */ package org.mvndaemon.mvnd.common; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; +import java.io.InputStream; +import java.lang.reflect.Constructor; import java.nio.file.Files; import java.nio.file.Path; -import java.util.stream.Stream; + +import org.codehaus.plexus.classworlds.ClassWorld; +import org.codehaus.plexus.classworlds.launcher.Launcher; +import org.codehaus.plexus.classworlds.realm.ClassRealm; public class MavenDaemon { public static void main(String[] args) throws Exception { - final Path mvndHome = Environment.MVND_HOME.asPath(); - URL[] classpath = Stream.concat( - /* jars */ - Stream.of("lib/ext", "lib", "boot") - .map(mvndHome::resolve) - .flatMap((Path p) -> { - try { - return Files.list(p); - } catch (java.io.IOException e) { - throw new RuntimeException("Could not list " + p, e); - } - }) - .filter(p -> { - final String fileName = p.getFileName().toString(); - return fileName.endsWith(".jar") && !fileName.startsWith("mvnd-client-"); - }) - .filter(Files::isRegularFile), - /* resources */ - Stream.of(mvndHome.resolve("conf"), mvndHome.resolve("conf/logging"))) - .map(Path::normalize) - .map(Path::toUri) - .map(uri -> { - try { - return uri.toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - }) - .toArray(URL[]::new); - ClassLoader loader = new URLClassLoader(classpath, null) { + Path mvndHome = Environment.MVND_HOME.asPath(); + Launcher launcher = new Launcher(); + launcher.setSystemClassLoader(new ClassLoader(ClassLoader.getPlatformClassLoader()) { + @Override protected Class<?> findClass(String name) throws ClassNotFoundException { - try { - return super.findClass(name); - } catch (ClassNotFoundException e) { + if (name.startsWith("org.codehaus.plexus.classworlds.") + || name.startsWith("org.codehaus.classworlds.")) { return MavenDaemon.class.getClassLoader().loadClass(name); } + throw new ClassNotFoundException(name); } - - @Override - public URL getResource(String name) { - URL url = super.getResource(name); - if (url == null) { - url = MavenDaemon.class.getClassLoader().getResource(name); - } - return url; - } - }; - Thread.currentThread().setContextClassLoader(loader); - Class<?> clazz = loader.loadClass("org.mvndaemon.mvnd.daemon.Server"); - try (AutoCloseable server = (AutoCloseable) clazz.getConstructor().newInstance()) { + }); + try (InputStream in = Files.newInputStream(mvndHome.resolve("bin/m2.conf"))) { Review Comment: Fixed and as a result I could also remove the custom ClassRealmManager, making the code even simpler. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org