private Path extractIfRequired(final Path buildDir) throws MojoFailureException, MojoExecutionException { if (jbossHome != null) { // we do not need to download WildFly return Paths.get(jbossHome); } final String artifact = ArtifactNameSplitter.of(this.artifact) .setArtifactId(artifactId) .setClassifier(classifier) .setGroupId(groupId) .setPackaging(packaging) .setVersion(version) .asString(); final Path result = artifactResolver.resolve(project, artifact).toPath(); final Path target = buildDir.resolve(WILDFLY_DIR); // Delete the target if it exists if (Files.exists(target)) { try { Archives.deleteDirectory(target); } catch (IOException e) { throw new MojoFailureException("Could not delete target directory: " + target, e); } } try { Archives.unzip(result, target); final Iterator<Path> iterator = Files.newDirectoryStream(target).iterator(); if (iterator.hasNext()) return iterator.next(); } catch (IOException e) { throw new MojoFailureException("Artifact was not successfully extracted: " + result, e); } throw new MojoFailureException("Artifact was not successfully extracted: " + result); }