protected String getJModExecutable()

in src/main/java/org/apache/maven/plugins/jmod/AbstractJModMojo.java [75:146]


    protected String getJModExecutable()
        throws IOException
    {
        Toolchain tc = getToolchain();

        String jModExecutable = null;
        if ( tc != null )
        {
            jModExecutable = tc.findTool( "jmod" );
        }

        String jModCommand = "jmod" + ( SystemUtils.IS_OS_WINDOWS ? ".exe" : "" );

        File jModExe;

        if ( StringUtils.isNotEmpty( jModExecutable ) )
        {
            jModExe = new File( jModExecutable );

            if ( jModExe.isDirectory() )
            {
                jModExe = new File( jModExe, jModCommand );
            }

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

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

        // ----------------------------------------------------------------------
        // Try to find jmod from System.getProperty( "java.home" )
        // By default, System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME
        // should be in the JDK_HOME
        // ----------------------------------------------------------------------
        jModExe = new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "bin", jModCommand );

        // ----------------------------------------------------------------------
        // Try to find jmod from JAVA_HOME environment variable
        // ----------------------------------------------------------------------
        if ( !jModExe.exists() || !jModExe.isFile() )
        {
            Properties env = CommandLineUtils.getSystemEnvVars();
            String javaHome = env.getProperty( "JAVA_HOME" );
            if ( StringUtils.isEmpty( javaHome ) )
            {
                throw new IOException( "The environment variable JAVA_HOME is not correctly set." );
            }
            if ( ( !new File( javaHome ).getCanonicalFile().exists() )
                || ( new File( javaHome ).getCanonicalFile().isFile() ) )
            {
                throw new IOException( "The environment variable JAVA_HOME=" + javaHome
                    + " doesn't exist or is not a valid directory." );
            }

            jModExe = new File( javaHome + File.separator + "bin", jModCommand );
        }

        if ( !jModExe.getCanonicalFile().exists() || !jModExe.getCanonicalFile().isFile() )
        {
            throw new IOException( "The jmod executable '" + jModExe
                + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable." );
        }

        return jModExe.getAbsolutePath();
    }