From efdde34094126d3d0b5ea227bd84252bb783340a Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Wed, 30 Aug 2017 10:23:48 +0100 Subject: [PATCH] [MNG-6275] Maven Embedder compatible fix - Embedded sets up a classloader to mimic the boot classpath based on parsing the classworldConf - This 'bootLoader' is then installed as the context classloader in the current thread - By default, a running JVM will start with a thread context classloader of 'null' to indicate the system classloader should be used - This change switches to follow the 'correct' behaviour of following the context classloader and falling back to the system class loader only in the case where the context classloader is null. - For running from the CLI, we expect that the thread context classloader will always be null so this should be as before - For running from embedder, we expect that the thread context classloader will have been correctly configured, so this should behave as intended --- .../org/apache/maven/classrealm/DefaultClassRealmManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java b/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java index 532cfd082f1..23008c99536 100644 --- a/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java +++ b/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java @@ -120,7 +120,9 @@ private ClassRealm newRealm( String id ) { try { - ClassRealm classRealm = world.newRealm( realmId, PARENT_CLASSLOADER ); + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + ClassRealm classRealm = world.newRealm( realmId, contextClassLoader == null + ? PARENT_CLASSLOADER : contextClassLoader ); if ( logger.isDebugEnabled() ) {