Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions client/src/com/mirth/connect/client/ui/ClientPrerequisites.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mitch Gaffigan <mitch@gaffigan.net>

package com.mirth.connect.client.ui;

/** Utility class to check if the client prerequisites are met. */
public class ClientPrerequisites {

private ClientPrerequisites() {
}

/** Checks if the client prerequisites are met. */
public static boolean isAcceptable() {
// Can't meaningfully check for Java 17 since the entrypoint is compiled with
// class file version 61, which will fail to load on Java 8.
return hasJavaFx();
}

private static boolean hasJavaFx() {
// Use JPMS to check for JavaFX - the classes are on the classpath
// even in Java SE, but the module will not be present except in FX
return ModuleLayer.boot().findModule("javafx.graphics").isPresent();
}
}
20 changes: 20 additions & 0 deletions client/src/com/mirth/connect/client/ui/Mirth.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
Expand Down Expand Up @@ -253,6 +254,12 @@ public static void initUIManager() {
* String[]
*/
public static void main(String[] args) {
if (!ClientPrerequisites.isAcceptable()) {
showUnsupportedJreDialog();
System.exit(1);
return;
}

CommandLineOptions opts = new CommandLineOptions(args);

if (StringUtils.isNotBlank(opts.getProtocols())) {
Expand All @@ -267,6 +274,19 @@ public static void main(String[] args) {
start(opts.getServer(), opts.getVersion(), opts.getUsername(), opts.getPassword());
}

private static void showUnsupportedJreDialog() {
var message = String.format(
"%s Client requires Java 17 or newer with JavaFX (JFX).%n%n"
+ "Detected Java runtime: %s%n%nPlease relaunch the client with a supported JRE.",
BrandingConstants.PRODUCT_NAME, System.getProperty("java.version"));

try {
JOptionPane.showMessageDialog(null, message, "Unsupported Java Runtime", JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
System.err.println(message);
}
}

private static void start(final String server, final String version, final String username, final String password) {
// disable the velocity logging
Logger velocityLogger = LogManager.getLogger(RuntimeConstants.DEFAULT_RUNTIME_LOG_NAME);
Expand Down
Loading