Package org.freeplane.launcher

# Class Launcher

java.lang.Object
org.freeplane.launcher.Launcher

public class Launcher extends Object
This class can be used to run freeplane instance from an application and to obtain its `Controller` object. To run a headless Freeplane instance use `Launcher.create().launchHeadless()`, to run a freeplane with complete user UI use `Launcher.create().launch()`

     Code Example:

    	public static void createNewMindMap(File freeplaneInstallationDirectory, final File newMapFile) {
    		final Launcher launcher = Launcher.createForInstallation(freeplaneInstallationDirectory).disableSecurityManager();
    		HeadlessMapCreator mapCreator = launcher.launchHeadless();
    		final Map map = mapCreator.load(TestApp.class.getResource("/templateFile.mm")).unsetMapLocation().getMap();
    		final Node childNode = map.getRoot().createChild();
    		String value = "hello world";
    		childNode.setText(value);
    		final String nodeText = (String) mapCreator.script("node.to.text", "groovy").executeOn(childNode);
    		System.out.println("Read node value: " + nodeText);
    		if(! nodeText.equals(value))
    			throw new AssertionError("unexpected value returned");
    		map.saveAs(newMapFile);
    		System.out.println("Saved file " + newMapFile.getAbsolutePath());
    		launcher.shutdown();
    	}

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Launcher`
  `create()`
  Creates Launcher for starting embedded Freeplane instance.
  `static Launcher`
  `createForInstallation(File freeplaneInstallationDirectory)`
  Creates Launcher for starting embedded Freeplane instance.
  `Launcher`
  `disableSecurityManager()`
  Disables security manager for launched Freeplane instance.
  `HeadlessMapCreator`
  `launchHeadless()`
  Launchs Freeplane without UI and returns HeadlessMapCreator instance.
  `Controller`
  `launchWithUI(String[] args)`
  Launchs Freeplane with UI and returns Controller instance.
  `static void`
  `main(String[] args)`
  `void`
  `shutdown()`
  The method should be call on application exit to shutdown embedded Freeplane instance.
  `Launcher`
  `userDirectory(File userDirectory)`
  Sets user configuration directory (without the version).
  `Launcher`
  `userDirectory(String userDirectory)`
  Sets user configuration directory (without the version).

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### main

    public static void main(String[] args)

  - ### createForInstallation

    public static Launcher createForInstallation(File freeplaneInstallationDirectory)
    Creates Launcher for starting embedded Freeplane instance.
    Parameters:
      `freeplaneInstallationDirectory` - Path to freeplane installation directory Only one Launcher per JVM can be created.
    Throws:
      `IllegalStateException` - is launcher already was created.

  - ### create

    public static Launcher create()
    Creates Launcher for starting embedded Freeplane instance. Freeplane installation directory is defined by location of jar file containing this class. Only one Launcher per JVM can be created.
    Throws:
      `IllegalStateException` - is launcher already was created.

  - ### launchHeadless

    public HeadlessMapCreator launchHeadless()
    Launchs Freeplane without UI and returns HeadlessMapCreator instance.
    Throws:
      `IllegalStateException` - is Freeplane was already launched.

  - ### launchWithUI

    public Controller launchWithUI(String[] args)
    Launchs Freeplane with UI and returns Controller instance. All API methods should be called from the swing event thread to avoid race conditions.
    Throws:
      `IllegalStateException` - is Freeplane was already launched.

  - ### shutdown

    public void shutdown()
    The method should be call on application exit to shutdown embedded Freeplane instance. No Freeplane objects may be used after the shutdown is called. It destroys some class loaders and invalidates all related classes and objects.

  - ### disableSecurityManager

    public Launcher disableSecurityManager()
    Disables security manager for launched Freeplane instance.

  - ### userDirectory

    public Launcher userDirectory(File userDirectory)
    Sets user configuration directory (without the version).

  - ### userDirectory

    public Launcher userDirectory(String userDirectory)
    Sets user configuration directory (without the version).