-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathLaunchJFX.java
More file actions
43 lines (40 loc) · 1.88 KB
/
Copy pathLaunchJFX.java
File metadata and controls
43 lines (40 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package io.fair_acc.sample;
import javafx.application.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Helper class to launch JavaFX applications without manually adding modules and exports to the java command line.
* Add a run configuration for this class in the arguments tab and add as program argument:
* <ul>
* <li>for Eclipse IDE: "${java_type_name}"</li>
* <li>for Intellij IDE: "$FileClass$"</li>
* </ul>
*
* Then, any JavaFX Application Class can be run by selecting it in the Package Explorer and running this run
* configuration. <br>
* To be able to run JavaFX Applications outside of the chartfx project also add a classpath entry of type "Advanced",
* "Variable", "${project_classpath}", but there is no way to add the current projects dependencies to the classpath,
* yet.
*
* See <a href="https://stackoverflow.com/a/55300492">Stackoverflow: How to add JavaFX runtime to Eclipse in Java11 (2b)</a>
* @author akrimm
*/
public class LaunchJFX { // NOMEN EST OMEN
private static final Logger LOGGER = LoggerFactory.getLogger(LaunchJFX.class);
public static void main(final String[] args) throws ClassNotFoundException {
if (args.length < 1 || args[0].contains(LaunchJFX.class.getName())) {
LOGGER.atInfo().log("no argument provided");
} else {
try {
Class<? extends Application> clazz = Class.forName(args[0]).asSubclass(Application.class);
if (Application.class.isAssignableFrom(clazz)) {
Application.launch(clazz);
} else {
LOGGER.atInfo().addArgument(clazz).log("{} is not an Application - starting default view");
}
} catch (ClassCastException e) {
LOGGER.atInfo().addArgument(args[0]).log("{} is not an Application - starting default view");
}
}
}
}