private String getJLinkExecutable()

in src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkToolchainExecutor.java [112:148]


    private String getJLinkExecutable() {
        Optional<Toolchain> toolchain = getToolchain();

        if (!toolchain.isPresent()) {
            getLog().error("Either JDK9+ or a toolchain "
                    + "pointing to a JDK9+ containing a jlink binary is required.");
            getLog().info("See https://maven.apache.org/guides/mini/guide-using-toolchains.html "
                    + "for mor information.");
            throw new IllegalStateException("Running on JDK8 and no toolchain found.");
        }

        String jLinkExecutable =
                toolchain.orElseThrow(NoSuchElementException::new).findTool("jlink");

        if (jLinkExecutable.isEmpty()) {
            throw new IllegalStateException(
                    "The jlink executable '" + jLinkExecutable + "' doesn't exist or is not a file.");
        }

        // TODO: Check if there exist a more elegant way?
        String jLinkCommand = "jlink" + (isOSWindows() ? ".exe" : "");

        File jLinkExe = new File(jLinkExecutable);

        if (jLinkExe.isDirectory()) {
            jLinkExe = new File(jLinkExe, jLinkCommand);
        }

        if (isOSWindows() && jLinkExe.getName().indexOf('.') < 0) {
            jLinkExe = new File(jLinkExe.getPath() + ".exe");
        }

        if (!jLinkExe.isFile()) {
            throw new IllegalStateException("The jlink executable '" + jLinkExe + "' doesn't exist or is not a file.");
        }
        return jLinkExe.getAbsolutePath();
    }