Creates a new JVM. If the {@code javaHome} is {@code null} the {@linkplain #current() current} JVM is returned.

@param javaHome the path to the Java home

@return a JVM descriptor based on the Java home path
191450
static Jvm of(final Path javaHome) {
        if (javaHome == null || javaHome.equals(JAVA_HOME)) {
            return DEFAULT;
        }
        final Path path = validateJavaHome(javaHome);
        return new Jvm(path, isModularJavaHome(path));
    }
207825
public static DomainCommandBuilder of(final String wildflyHome, final String javaHome) {
        return new DomainCommandBuilder(Environment.validateWildFlyDir(wildflyHome), Jvm.of(javaHome));
    }
327466
public static File getMavenHome() throws Exception {
        final String command;
        switch (OS.current()) {
        case LINUX:
        case MAC:
            command = "mvn";
            break;
        case WINDOWS:
            command = "mvn.bat";
            break;
        default:
            throw new IllegalStateException("invalid o/s");
        }
        String pathVar = System.getenv("PATH");
        String[] pathArray = pathVar.split(File.pathSeparator);
        for (String path : pathArray) {
            File file = new File(path, command);
            if (file.exists() && file.isFile() && file.canExecute()) {
                /** unwrap symbolic links */
                File exec = file.getCanonicalFile();
                /** assume ${maven.home}/bin/exec convention */
                File home = exec.getParentFile().getParentFile();
                return home;
            }
        }
        throw new IllegalStateException("Maven home not found.");
    }
943981
public BeanId find(EJSHome home, Serializable pkey, boolean isHome)
    {
        int hashValue = BeanId.computeHashValue(home.j2eeName, pkey, isHome);

        BeanId[] buckets = this.ivBuckets;
        BeanId element = buckets[(hashValue & 0x7FFFFFFF) % buckets.length];

        if (element == null || !element.equals(home, pkey, isHome))
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            {
                ++ivCacheFinds;
                Tr.debug(tc, "BeanId not found in BeanId Cache : " +
                             ivCacheHits + " / " + ivCacheFinds);
            }
            element = new BeanId(home, pkey, isHome);
        }
        else
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            {
                ++ivCacheFinds;
                ++ivCacheHits;
                Tr.debug(tc, "BeanId found in BeanId Cache : " +
                             ivCacheHits + " / " + ivCacheFinds);
            }
        }

        return element;
    }
1262289
@Override
    public EJBHome getEJBHome() throws RemoteException
    {
        EJSWrapper homeWrapper = wrapperManager.getWrapper(beanId.getHome().getId()).getRemoteWrapper();
        Object homeRef = container.getEJBRuntime().getRemoteReference(homeWrapper);
        return (EJBHome) PortableRemoteObject.narrow(homeRef, EJBHome.class);
    }
679287
@XmlElementDecl(namespace = "http://www.ibm.com/websphere/wim", name = "homePostalAddress")
    public JAXBElement<String> createHomePostalAddress(String value) {
        return new JAXBElement<String>(_HomePostalAddress_QNAME, String.class, null, value);
    }
1215931
private SchemaFactory _newFactory(String schemaLanguage) {
        SchemaFactory sf;
        String propertyName = SERVICE_CLASS.getName() + ":" + schemaLanguage;

        // system property look up
        try {
            if (debug) debugPrintln("Looking up system property '"+propertyName+"'" );
            String r = System.getProperty(propertyName);
            if (r != null && r.length() > 0) {
                if (debug) debugPrintln("The value is '"+r+"'");
                sf = createInstance(r);
                if(sf!=null)    return sf;
            }
            else if (debug) {
                debugPrintln("The property is undefined.");
            }
        }
        // The VM ran out of memory or there was some other serious problem. Re-throw.
        catch (VirtualMachineError vme) {
            throw vme;
        }
        // ThreadDeath should always be re-thrown
        catch (ThreadDeath td) {
            throw td;
        }
        catch (Throwable t) {
            if( debug ) {
                debugPrintln("failed to look up system property '"+propertyName+"'" );
                t.printStackTrace();
            }
        }

        // try to read from $java.home/lib/jaxp.properties
        try {
            String factoryClassName = CacheHolder.cacheProps.getProperty(propertyName);
            if (debug) debugPrintln("found " + factoryClassName + " in $java.home/jaxp.properties");

            if (factoryClassName != null) {
                sf = createInstance(factoryClassName);
                if(sf != null){
                    return sf;
                }
            }
        } catch (Exception ex) {
            if (debug) {
                ex.printStackTrace();
            }
        }

        // try META-INF/services files
        for (URL resource : createServiceFileIterator()) {
            if (debug) debugPrintln("looking into " + resource);
            try {
                sf = loadFromServicesFile(schemaLanguage,resource.toExternalForm(),
                        resource.openStream());
                if(sf!=null)    return sf;
            } catch(IOException e) {
                if( debug ) {
                    debugPrintln("failed to read "+resource);
                    e.printStackTrace();
                }
            }
        }

        // platform defaults
        if (schemaLanguage.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI) || schemaLanguage.equals(W3C_XML_SCHEMA10_NS_URI)) {
            if (debug) debugPrintln("attempting to use the platform default XML Schema 1.0 validator");
            return createInstance("org.apache.xerces.jaxp.validation.XMLSchemaFactory");
        }
        else if (schemaLanguage.equals(W3C_XML_SCHEMA11_NS_URI)) {
            if (debug) debugPrintln("attempting to use the platform default XML Schema 1.1 validator");
            return createInstance("org.apache.xerces.jaxp.validation.XMLSchema11Factory");
        }

        if (debug) debugPrintln("all things were tried, but none was found. bailing out.");
        return null;
    }
565431
def find_libjvm(self, java_home):
        
        found_jamvm = False
        non_supported_jvm = ('cacao', 'jamvm')
        found_non_supported_jvm = False

        # Look for the file
        for root, _, names in os.walk(java_home):
            if self._libfile in names:
                # Found it, but check for non supported jvms
                candidate = os.path.split(root)[1]
                if candidate in non_supported_jvm:
                    found_non_supported_jvm = True
                    continue # maybe we will find another one?
                return os.path.join(root, self._libfile)

        else:
            if found_non_supported_jvm:
                raise JVMNotSupportedException("Sorry '{0}' is known to be "
                                               "broken. Please ensure your "
                                               "JAVA_HOME contains at least "
                                               "another JVM implementation "
                                               "(eg. server)"
                                               .format(candidate))
            # File not found
            raise JVMNotFoundException("Sorry no JVM could be found. "
                                       "Please ensure your JAVA_HOME "
                                       "environment variable is pointing "
                                       "to correct installation.")
6759
@Override
    public EJBHome getEJBHome()
    {
        try
        {
            EJSWrapper wrapper = home.getWrapper().getRemoteWrapper();
            Object wrapperRef = container.getEJBRuntime().getRemoteReference(wrapper);

            // The EJB spec does not require us to narrow to the actual home
            // interface, but since we have to narrow to EJBHome anyway, we
            // might as well narrow to the specific interface.  It seems like it
            // might be an oversight anyway given that the spec does require
            // SessionContext.getEJBObject to narrow.
            return (EJBHome) PortableRemoteObject.narrow(wrapperRef, home.beanMetaData.homeInterfaceClass);
        } catch (IllegalStateException ise) { // d116480
            // FFDC not logged for this spec required scenario
            throw ise;
        } catch (Exception ex) {
            // p97440 - start of change

            // This should never happen. Something is wrong.
            // Need to throw a runtime exception since this is a
            // Java EE architected interface that does not allow a checked
            // exceptions to be thrown. So, throw ContainerEJBException.
            FFDCFilter.processException(ex, CLASS_NAME + ".getEJBHome", "522", this);
            ContainerEJBException ex2 = new ContainerEJBException("Failed to get the wrapper for home.", ex);

            Tr.error(tc
                     , "CAUGHT_EXCEPTION_THROWING_NEW_EXCEPTION_CNTR0035E"
                     , new Object[] { ex, ex2.toString() }); // d194031

            throw ex2;

            // p97440 - end of change
        }

    }
1163130
public static DomainCommandBuilder of(final Path wildflyHome) {
        return new DomainCommandBuilder(Environment.validateWildFlyDir(wildflyHome), Jvm.current());
    }
1347609
function getJavaHome() {
	if(!java_home) {
		if(typeof process.env.JAVA_HOME === 'string' && process.env.JAVA_HOME) {
			java_home = process.env.JAVA_HOME;
		} else if(process.platform === 'darwin') {
			java_home = cp.execSync("/usr/libexec/java_home").toString().trim();
		} else if(process.platform === 'linux') {
			//TODO anything magical we can do here to compute the 'default' Java?
		} else if(process.platform === 'win32') {
			//TODO not sure Windows has any way to know where Java is installed
		}
	}
	return java_home;
}
600632
@Override
	public SimpleOrderedMap<Object> create(ComponentVersion version, Boolean encode) throws IOException {
		return getVersion();
	}
1272770
@Override
    public ConnectionFactory createConnectionFactory(JmsJcaConnectionFactory jcaConnectionFactory) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createConnectionFactory", jcaConnectionFactory);
        ConnectionFactory cf = new JmsManagedConnectionFactoryImpl(jcaConnectionFactory);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "createConnectionFactory", cf);
        return cf;
    }
1117614
@SuppressWarnings("deprecation")
	public static MailerRegularBuilderImpl withSMTPServer(@Nullable final String host, @Nullable final Integer port, @Nullable final String username, @Nullable final String password) {
		return new MailerRegularBuilderImpl().withSMTPServer(host, port, username, password);
	}
365808
protected void createFindbugsEngine() {
        findbugsEngine = new Java();
        findbugsEngine.setProject(getProject());
        findbugsEngine.setTaskName(getTaskName());
        findbugsEngine.setFork(true);
        if (jvm.length() > 0) {
            findbugsEngine.setJvm(jvm);
        }
        findbugsEngine.setTimeout(timeout);

        if (debug) {
            jvmargs = jvmargs + " -Dfindbugs.debug=true";
        }
        jvmargs = jvmargs + " -Dfindbugs.hostApp=FBAntTask";
        findbugsEngine.createJvmarg().setLine(jvmargs);

        // Add JVM arguments for system properties
        for (SystemProperty systemProperty : systemPropertyList) {
            String jvmArg = "-D" + systemProperty.getName() + "=" + systemProperty.getValue();
            findbugsEngine.createJvmarg().setValue(jvmArg);
        }

        if (homeDir != null) {
            // Use findbugs.home to locate findbugs.jar and the standard
            // plugins. This is the usual means of initialization.
            File findbugsLib = new File(homeDir, "lib");
            if (!findbugsLib.exists() && "lib".equals(homeDir.getName())) {
                findbugsLib = homeDir;
                homeDir = homeDir.getParentFile();
            }
            File findbugsLibFindBugs = new File(findbugsLib, "spotbugs.jar");
            // log("executing using home dir [" + homeDir + "]");
            if (findbugsLibFindBugs.exists()) {
                findbugsEngine.setClasspath(new Path(getProject(), findbugsLibFindBugs.getPath()));
            } else {
                throw new IllegalArgumentException("Can't find spotbugs.jar in " + findbugsLib);
            }
            findbugsEngine.createJvmarg().setValue("-Dspotbugs.home=" + homeDir.getPath());
        } else {
            // Use an explicitly specified classpath and list of plugin Jars
            // to initialize. This is useful for other tools which may have
            // FindBugs installed using a non-standard directory layout.

            findbugsEngine.setClasspath(classpath);
        }
        if (pluginList != null) {
            addArg("-pluginList");
            addArg(pluginList.toString());
        }
        // Set the main class to be whatever the subclass's constructor
        // specified.
        findbugsEngine.setClassname(mainClass);
    }
91533
public EJBLocalHome getLocalHome(String jndiHomeName) throws ServiceLocatorException {
		EJBLocalHome home = null;
		try {
			home = (EJBLocalHome) ic.lookup(jndiHomeName);
		} catch (NamingException ne) {
			throw new ServiceLocatorException(ne);
		} catch (Exception e) {
			throw new ServiceLocatorException(e);
		}
		return home;
	}
1221760
private static boolean isModular(final Path javaHome) {
        boolean result;
        final List<String> cmd = new ArrayList<>();
        cmd.add(resolveJavaCommand(javaHome));
        cmd.add("--add-modules=java.se");
        cmd.add("-version");
        final ProcessBuilder builder = new ProcessBuilder(cmd);
        Process process = null;
        Path stdout = null;
        try {
            // Create a temporary file for stdout
            stdout = Files.createTempFile("stdout", ".txt");
            process = builder.redirectErrorStream(true)
                    .redirectOutput(stdout.toFile()).start();

            if (process.waitFor(1, TimeUnit.SECONDS)) {
                result = process.exitValue() == 0;
            } else {
                result = false;
            }
        } catch (IOException | InterruptedException e) {
            result = false;
        } finally {
            if (process != null && process.isAlive()) {
                process.destroyForcibly();
            }
            if (stdout != null) {
                try {
                    Files.deleteIfExists(stdout);
                } catch (IOException ignore) {
                }
            }
        }
        return result;
    }