Skip to content

Commit df599f8

Browse files
committed
Added client prerequisite check
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent bfe3348 commit df599f8

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: MPL-2.0
2+
// SPDX-FileCopyrightText: Mitch Gaffigan <mitch@gaffigan.net>
3+
4+
package com.mirth.connect.client.ui;
5+
6+
/** Utility class to check if the client prerequisites are met. */
7+
public class ClientPrerequisites {
8+
9+
private ClientPrerequisites() {
10+
}
11+
12+
/** Checks if the client prerequisites are met. */
13+
public static boolean isAcceptable() {
14+
// Can't meaningfully check for Java 17 since the entrypoint is compiled with
15+
// class file version 61, which will fail to load on Java 8.
16+
return hasJavaFx();
17+
}
18+
19+
private static boolean hasJavaFx() {
20+
// Use JPMS to check for JavaFX - the classes are on the classpath
21+
// even in Java SE, but the module will not be present except in FX
22+
return ModuleLayer.boot().findModule("javafx.graphics").isPresent();
23+
}
24+
}

client/src/com/mirth/connect/client/ui/Mirth.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javax.imageio.ImageIO;
1414
import javax.swing.ImageIcon;
1515
import javax.swing.InputMap;
16+
import javax.swing.JOptionPane;
1617
import javax.swing.KeyStroke;
1718
import javax.swing.SwingUtilities;
1819
import javax.swing.ToolTipManager;
@@ -253,6 +254,12 @@ public static void initUIManager() {
253254
* String[]
254255
*/
255256
public static void main(String[] args) {
257+
if (!ClientPrerequisites.isAcceptable()) {
258+
showUnsupportedJreDialog();
259+
System.exit(1);
260+
return;
261+
}
262+
256263
CommandLineOptions opts = new CommandLineOptions(args);
257264

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

277+
private static void showUnsupportedJreDialog() {
278+
var message = String.format(
279+
"%s Client requires Java 17 or newer with JavaFX (JFX).%n%n"
280+
+ "Detected Java runtime: %s%n%nPlease relaunch the client with a supported JRE.",
281+
BrandingConstants.PRODUCT_NAME, System.getProperty("java.version"));
282+
283+
try {
284+
JOptionPane.showMessageDialog(null, message, "Unsupported Java Runtime", JOptionPane.ERROR_MESSAGE);
285+
} catch (Throwable t) {
286+
System.err.println(message);
287+
}
288+
}
289+
270290
private static void start(final String server, final String version, final String username, final String password) {
271291
// disable the velocity logging
272292
Logger velocityLogger = LogManager.getLogger(RuntimeConstants.DEFAULT_RUNTIME_LOG_NAME);

0 commit comments

Comments
 (0)