1 package net.sf.openrocket.startup;
3 import java.awt.GraphicsEnvironment;
4 import java.lang.reflect.InvocationTargetException;
5 import java.lang.reflect.Method;
7 import javax.swing.JOptionPane;
11 * A startup class that checks that a suitable JRE environment is being run.
12 * If the environment is too old the execution is canceled, and if OpenJDK is being
13 * used warns the user of problems and confirms whether to continue.
15 * Note: This class must be Java 1.4 compatible and calls the next class using
18 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
20 public class Startup {
22 public static final String START_CLASS = "net.sf.openrocket.gui.main.BasicFrame";
24 public static final int REQUIRED_MAJOR_VERSION = 1;
25 public static final int REQUIRED_MINOR_VERSION = 6;
28 public static void main(String[] args) {
34 // Load and execute START_CLASS
37 Class cls = Class.forName(START_CLASS);
38 Method m = cls.getMethod("main", new Class[] {String[].class});
39 m.invoke(null, new Object[] { args });
41 } catch (ClassNotFoundException e) {
43 error(new String[] {"Error starting main class!", "Please report a bug."});
44 } catch (NoSuchMethodException e) {
46 error(new String[] {"Error starting main class!", "Please report a bug."});
47 } catch (InvocationTargetException e) {
49 error(new String[] {"Error starting main class!", "Please report a bug."});
50 } catch (IllegalAccessException e) {
52 error(new String[] {"Error starting main class!", "Please report a bug."});
59 * Check that the JRE version is high enough.
61 private static void checkVersion() {
62 String[] version = System.getProperty("java.specification.version", "").split("\\.");
64 String jreName = System.getProperty("java.vm.name", "(unknown)");
65 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
66 String jreVendor = System.getProperty("java.vendor", "(unknown)");
71 major = Integer.parseInt(version[0]);
72 minor = Integer.parseInt(version[1]);
74 if (major < REQUIRED_MAJOR_VERSION ||
75 (major == REQUIRED_MAJOR_VERSION && minor < REQUIRED_MINOR_VERSION)) {
76 error(new String[] {"Java SE version 6 is required to run OpenRocket.",
77 "You are currently running " + jreName + " version " +
78 jreVersion + " by " + jreVendor});
81 } catch (RuntimeException e) {
83 confirm(new String[] {"The Java version in use could not be detected.",
84 "OpenRocket requires at least Java SE 6.",
93 * Check that the JRE is not running headless.
95 private static void checkHead() {
97 if (GraphicsEnvironment.isHeadless()) {
99 System.err.println("OpenRocket cannot currently be run without the graphical " +
101 System.err.println();
109 * Check whether OpenJDK is being used, and if it is warn the user about
110 * problems and confirm whether to continue.
112 private static void checkOpenJDK() {
114 if (System.getProperty("java.runtime.name", "").toLowerCase().indexOf("icedtea")>=0 ||
115 System.getProperty("java.vm.name", "").toLowerCase().indexOf("openjdk")>=0) {
117 String jreName = System.getProperty("java.vm.name", "(unknown)");
118 String jreVersion = System.getProperty("java.runtime.version", "(unknown)");
119 String jreVendor = System.getProperty("java.vendor", "(unknown)");
121 confirm(new String[] {"OpenJDK is known to have problems running OpenRocket.",
123 "You are currently running " + jreName + " version " +
124 jreVersion + " by " + jreVendor,
125 "Do you want to continue?"});
134 * Presents an error message to the user and exits the application.
136 * @param message an array of messages to present.
138 private static void error(String[] message) {
140 System.err.println();
141 System.err.println("Error starting OpenRocket:");
142 System.err.println();
143 for (int i=0; i < message.length; i++) {
144 System.err.println(message[i]);
146 System.err.println();
149 if (!GraphicsEnvironment.isHeadless()) {
151 JOptionPane.showMessageDialog(null, message, "Error starting OpenRocket",
152 JOptionPane.ERROR_MESSAGE);
161 * Presents the user with a message dialog and asks whether to continue.
162 * If the user does not select "Yes" the the application exits.
164 * @param message the message Strings to show.
166 private static void confirm(String[] message) {
168 if (!GraphicsEnvironment.isHeadless()) {
170 if (JOptionPane.showConfirmDialog(null, message, "Error starting OpenRocket",
171 JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {