FatJarDetector { public Result scan() throws MojoExecutionException { if (result == null) { if (!directory.exists()) { return null; } String[] jarOrWars = directory.list((dir, name) -> name.endsWith(".war") || name.endsWith(".jar")); if (jarOrWars == null || jarOrWars.length == 0) { return null; } long maxSize = 0; for (String jarOrWar : jarOrWars) { File archiveFile = new File(directory, jarOrWar); try (JarFile archive = new JarFile(archiveFile)){ Manifest mf = archive.getManifest(); Attributes mainAttributes = mf.getMainAttributes(); if (mainAttributes != null) { String mainClass = mainAttributes.getValue("Main-Class"); if (mainClass != null) { long size = archiveFile.length(); if (size > maxSize) { maxSize = size; result = new Result(archiveFile, mainClass, mainAttributes); } } } } catch (IOException e) { throw new MojoExecutionException("Cannot examine file " + archiveFile + " for the manifest"); } } } return result; } FatJarDetector(String dir); Result scan();  }
@Test public void simple() throws MojoExecutionException { URL testDirUrl = getClass().getResource("/fatjar-simple"); FatJarDetector detector = new FatJarDetector(getAbsolutePath(testDirUrl)); FatJarDetector.Result result = detector.scan(); assertNotNull(result); assertEquals(new File(getAbsolutePath(testDirUrl) + "/test.jar"), result.getArchiveFile()); assertEquals("org.springframework.boot.loader.JarLauncher", result.getMainClass()); assertEquals("Plexus Archiver", result.getManifestEntry("Archiver-Version")); }