AntennaUtils { public static Path computeInnerReplacementJarPath(Path jarPath){ Iterator<Path> jarPathIterator = getJarPathIteratorFromPath(jarPath); if(!jarPathIterator.hasNext()){ throw new ExecutionException("Tried to computeInnerReplacementPath from broken Path"); } Path cleanedUp = jarPathIterator.next(); while(jarPathIterator.hasNext()){ final String basename = Optional.ofNullable(cleanedUp.getFileName()) .orElseThrow(() -> new ExecutionException("Error in computeInnerReplacementJarPath")) .toString(); final String parent = Optional.ofNullable(cleanedUp.getParent()) .orElseThrow(() -> new ExecutionException("Error in computeInnerReplacementJarPath")) .toString(); String cleanedUpBasename = replaceDotInJarExtension(basename); cleanedUp = Paths.get(parent, cleanedUpBasename, jarPathIterator.next().toString()); } return cleanedUp; } private  AntennaUtils(); static Iterator<Path> getJarPathIteratorFromPath(Path jarPath); static Path getJarPath(URL url); static Path getJarPath(Path jarPath); static String replaceDotInJarExtension(String path); static Path computeInnerReplacementJarPath(Path jarPath);  }
@Test public void computeInnerReplacementJarPathTest() { Path filePath = Paths.get("/some/path/to/file.jar/child.war/subChild.jar").toAbsolutePath(); Path computed = AntennaUtils.computeInnerReplacementJarPath(filePath); assertThat(computed).hasToString(toAbsolutePathname("/some/path/to/file_jar/child_war/subChild.jar")); }