# JVMSelector

Import: `import com.install4j.api.JVMSelector;`

```java
public class JVMSelector
```

With this class, you can retrieve the installed JVMs on Windows, Linux and Unix systems.
Additionally, you can set the preferred VM for your application.

| Type | Kind | Description |
|---|---|---|
## Nested types

| [JVMSelector.JVMLocation](JVMSelector.JVMLocation.md) | interface | The interface providing information about a JVM. |

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`getJVMLocations()`](#getjvmlocations) | `JVMLocation[]` | Returns JVMs found in standard locations. |
| [`getJVMLocations(String, String, boolean, File[])`](#getjvmlocations-string-string-boolean-file) | `JVMLocation[]` | Returns JVMs found in standard locations with the given version requirements. |
| [`getJVMLocation(File, String, String, boolean)`](#getjvmlocation-file-string-string-boolean) | `JVMLocation` | Checks if this directory contains a JVM with the specified parameters and returns the location object. |
| [`setPreferredJVM(String)`](#setpreferredjvm-string) | `void` | Set the preferred JRE/JDK for your application. |

### getJVMLocations()

```java
public static JVMLocation[] getJVMLocations()
```

Returns JVMs found in standard locations.
On Windows, the registry is used to get the JVMs.
On Linux/Unix and macOS, this method searches the usual locations for JVMs.
Please be aware that this method can take some time on Linux/Unix as it
executes java to gather version information.


**Returns:** an array of JVMLocation objects. See this class for more detail.

### getJVMLocations(String, String, boolean, File[])

```java
public static JVMLocation[] getJVMLocations(String minVersion, String maxVersion, boolean jdkOnly, File[] additionalLocations)
```

Returns JVMs found in standard locations with the given version requirements.
On Windows, the registry is used to get the JVMs.
On Linux/Unix and macOS, this method searches the usual locations for JVMs.
Please be aware that this method can take some time on Linux/Unix as it
executes java to gather version information.


**Parameters:**

- `minVersion` — the minimum java version
- `maxVersion` — the maximum java version
- `jdkOnly` — only JDKs
- `additionalLocations` — additional locations that should be tested for JVMs

**Returns:** an array of JVMLocation objects. See this class for more detail.

### getJVMLocation(File, String, String, boolean)

```java
public static JVMLocation getJVMLocation(File javaHome, String minVersion, String maxVersion, boolean jdkOnly)
```

Checks if this directory contains a JVM with the specified parameters and returns the location object.
The versions can be empty Strings if there should be no restriction.


**Parameters:**

- `javaHome` — the directory to check
- `minVersion` — the minimum java version
- `maxVersion` — the maximum java version
- `jdkOnly` — only JDKs

**Returns:** a JVMLocation object or null. See this class for more detail.

### setPreferredJVM(String)

```java
public static void setPreferredJVM(String javaHome)
```

Set the preferred JRE/JDK for your application. As long as this JRE/JDK exists and
fulfills the version requirement of your application, it will be used.
This method has no effect on macOS.


**Parameters:**

- `javaHome` — the base directory of the JDK/JRE.

