Returns the name of the launcher which has started this application. - Java java.lang

Java examples for java.lang:System

Description

Returns the name of the launcher which has started this application.

Demo Code

/*******************************************************************************
 * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany
 *                    Technical University Darmstadt, Germany
 *                    Chalmers University of Technology, Sweden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w w.  j  a v  a2  s .  c om*/
 *    Technical University Darmstadt - initial API and implementation and/or initial documentation
 *******************************************************************************/
//package com.java2s;
import java.io.File;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getLauncherName());
    }

    /**
     * Returns the name of the launcher which has started this application.
     * @return The name of the launcher which has started this application.
     */
    public static String getLauncherName() {
        File launcher = getLauncher();
        return launcher != null ? launcher.getName() : null;
    }

    /**
     * Returns the path to the launcher which has started this application.
     * @return The path to the launcher which has started this application.
     */
    public static File getLauncher() {
        String path = System.getProperty("-launcher");
        if (path != null) {
            return new File(path);
        } else {
            return null;
        }
    }
}

Related Tutorials