diff --git a/util/src/main/java/io/kubernetes/client/util/ModelMapper.java b/util/src/main/java/io/kubernetes/client/util/ModelMapper.java index 1271a60ccc..995b151e2d 100644 --- a/util/src/main/java/io/kubernetes/client/util/ModelMapper.java +++ b/util/src/main/java/io/kubernetes/client/util/ModelMapper.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; +import java.net.JarURLConnection; import java.net.URI; import java.net.URL; import java.net.URLDecoder; @@ -485,14 +486,26 @@ private static List getClassNamesFromPackage(ClassLoader classLoader, St private static void processJarPackage(URL packageURL, String packageName, String pkg, ArrayList names) throws IOException { String jarFileName = URLDecoder.decode(packageURL.getFile(), "UTF-8"); - jarFileName = jarFileName.substring(5, jarFileName.indexOf("!")); + JarFile jf = null; + // jar: client in repository; nested: client in a fat jar + if (jarFileName.startsWith("jar:") || jarFileName.startsWith("nested:")) { + jf = ((JarURLConnection) packageURL.openConnection()).getJarFile(); + } + // file: client is a file in target (unit test) + if (jarFileName.startsWith("file:") ) { + jarFileName = jarFileName.substring(5, jarFileName.indexOf("!")); + jf = new JarFile(jarFileName); + } + if (jf == null) { + logger.error("Loading classes from jar with error packageURL: {}", jarFileName); + return; + } logger.info("Loading classes from jar {}", jarFileName); - try (JarFile jf = new JarFile(jarFileName)) { - Enumeration jarEntries = jf.entries(); - while (jarEntries.hasMoreElements()) { - processJarEntry(jarEntries.nextElement(), packageName, pkg, names); - } + Enumeration jarEntries = jf.entries(); + while (jarEntries.hasMoreElements()) { + processJarEntry(jarEntries.nextElement(), packageName, pkg, names); } + jf.close(); } private static void processJarEntry(JarEntry jarEntry, String packageName, String pkg, ArrayList names) {