public static void restartApplication(final Runnable runBeforeRestart)
			throws IOException {
		try {
			// java binary
			final String java = System.getProperty("java.home") + "/bin/java";
			// vm arguments
			final List<String> vmArguments = ManagementFactory
					.getRuntimeMXBean().getInputArguments();
			final StringBuffer vmArgsOneLine = new StringBuffer();
			for (final String arg : vmArguments) {
				// if it's the agent argument : we ignore it otherwise the
				// address of the old application and the new one will be in
				// conflict
				if (!arg.contains("-agentlib")) {
					vmArgsOneLine.append(arg);
					vmArgsOneLine.append(" ");
				}
			}
			// init the command to execute, add the vm args
			final StringBuffer cmd = new StringBuffer("\"" + java + "\" "
					+ vmArgsOneLine);

			// program main and program arguments
			final String[] mainCommand = System.getProperty(SUN_JAVA_COMMAND)
					.split(" ");
			// program main is a jar
			if (mainCommand[0].endsWith(".jar")) {
				// if it's a jar, add -jar mainJar
				cmd.append("-jar " + new File(mainCommand[0]).getPath());
			} else {
				// else it's a .class, add the classpath and mainClass
				cmd.append("-cp \"" + System.getProperty("java.class.path")
						+ "\" " + mainCommand[0]);
			}
			// finally add program arguments
			for (int i = 1; i < mainCommand.length; i++) {
				cmd.append(" ");
				cmd.append(mainCommand[i]);
			}
			// execute the command in a shutdown hook, to be sure that all the
			// resources have been disposed before restarting the application
			Runtime.getRuntime().addShutdownHook(new Thread() {
				@Override
				public void run() {
					try {
						Runtime.getRuntime().exec(cmd.toString());
					} catch (final IOException e) {
						e.printStackTrace();
					}
				}
			});
			// execute some custom code before restarting
			if (runBeforeRestart != null) {
				runBeforeRestart.run();
			}
			// exit
			System.exit(0);
		} catch (final Exception e) {
			LOGGER.log(Level.SEVERE, Localization
					.translate("Utils.restartApplication.Exception"), e);
		}
	}