Class VMCommandLine


  • public class VMCommandLine
    extends Object
    This utility class permits to get the java command line for the current VM.
    Version:
    17.0 2020-01-04 14:41:35
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    vmutils
    • Method Detail

      • getExecutableFilename

        @Pure
        public static String getExecutableFilename​(String name)
        Replies a binary executable filename depending of the current platform.
        Parameters:
        name - is the name which must be converted into a binary executable filename.
        Returns:
        the binary executable filename.
      • getVMBinary

        @Pure
        public static String getVMBinary()
        Replies the current java VM binary.
        Returns:
        the binary executable filename that was used to launch the virtual machine.
      • launchVMWithClassPath

        public static Process launchVMWithClassPath​(Class<?> classToLaunch,
                                                    String classpath,
                                                    String... additionalParams)
                                             throws IOException
        Run a new VM with the given class path.
        Parameters:
        classToLaunch - is the class to launch.
        classpath - is the class path to use.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • launchVMWithClassPath

        public static Process launchVMWithClassPath​(String classToLaunch,
                                                    String classpath,
                                                    String... additionalParams)
                                             throws IOException
        Run a new VM with the given class path.
        Parameters:
        classToLaunch - is the class to launch.
        classpath - is the class path to use.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • launchVMWithClassPath

        public static Process launchVMWithClassPath​(Class<?> classToLaunch,
                                                    File[] classpath,
                                                    String... additionalParams)
                                             throws IOException
        Run a new VM with the given class path.
        Parameters:
        classToLaunch - is the class to launch.
        classpath - is the class path to use.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • launchVMWithClassPath

        public static Process launchVMWithClassPath​(String classToLaunch,
                                                    File[] classpath,
                                                    String... additionalParams)
                                             throws IOException
        Run a new VM with the given class path.
        Parameters:
        classToLaunch - is the class to launch.
        classpath - is the class path to use.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • launchVMWithJar

        public static Process launchVMWithJar​(File jarFile,
                                              String... additionalParams)
                                       throws IOException
        Run a jar file inside a new VM.
        Parameters:
        jarFile - is the jar file to launch.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • launchVM

        public static Process launchVM​(Class<?> classToLaunch,
                                       String... additionalParams)
                                throws IOException
        Run a new VM with the class path of the current VM.
        Parameters:
        classToLaunch - is the class to launch.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
      • launchVM

        public static Process launchVM​(String classToLaunch,
                                       String... additionalParams)
                                throws IOException
        Run a new VM with the class path of the current VM.
        Parameters:
        classToLaunch - is the class to launch.
        additionalParams - is the list of additional parameters
        Returns:
        the process that is running the new virtual machine, neither null
        Throws:
        IOException - when a IO error occurs.
        Since:
        6.2
      • saveVMParameters

        public static void saveVMParameters​(Class<?> classToLaunch,
                                            String... parameters)
        Save parameters that permit to relaunch a VM with relaunchVM().
        Parameters:
        classToLaunch - is the class which contains a main.
        parameters - is the parameters to pass to the main.
      • saveVMParameters

        public static void saveVMParameters​(String classToLaunch,
                                            String... parameters)
        Save parameters that permit to relaunch a VM with relaunchVM().
        Parameters:
        classToLaunch - is the class which contains a main.
        parameters - is the parameters to pass to the main.
        Since:
        6.2
      • saveVMParametersIfNotSet

        public static void saveVMParametersIfNotSet​(Class<?> classToLaunch,
                                                    String... parameters)
        Save parameters that permit to relaunch a VM with relaunchVM().
        Parameters:
        classToLaunch - is the class which contains a main.
        parameters - is the parameters to pass to the main.
      • saveVMParametersIfNotSet

        public static void saveVMParametersIfNotSet​(String classToLaunch,
                                                    String... parameters)
        Save parameters that permit to relaunch a VM with relaunchVM().
        Parameters:
        classToLaunch - is the class which contains a main.
        parameters - is the parameters to pass to the main.
        Since:
        6.2
      • getAllCommandLineParameters

        @Pure
        public static String[] getAllCommandLineParameters()
        Replies the command line including the options and the standard parameters.
        Returns:
        the command line.
      • getCommandLineParameters

        @Pure
        public static String[] getCommandLineParameters()
        Replies the command line parameters.
        Returns:
        the list of the parameters on the command line
      • shiftCommandLineParameters

        public static String shiftCommandLineParameters()
        Shift the command line parameters by one on the left. The first parameter is removed from the list.
        Returns:
        the removed element or null
      • getCommandLineOptions

        @Pure
        public static Map<String,​List<Object>> getCommandLineOptions()
        Replies the command line options.
        Returns:
        the list of options passed on the command line
      • getCommandLineOption

        @Pure
        public static List<Object> getCommandLineOption​(String name)
        Replies one command option.
        Parameters:
        name - is the name of the option
        Returns:
        the option value or null if the option is not on the command line.
      • hasCommandLineOption

        @Pure
        public static boolean hasCommandLineOption​(String name)
        Replies if an option was specified on the command line.
        Parameters:
        name - is the name of the option
        Returns:
        true if the option was found on the command line, otherwise false.
      • splitOptionsAndParameters

        public static void splitOptionsAndParameters​(String... optionDefinitions)
        Analyse the command line to extract the options.

        The options will be recognized thanks to the optionDefinitions. Each entry of optionDefinitions describes an option. They must have one of the following formats:

        • name: a simple option without value or flag,
        • name=s: an option with a mandatory string value,
        • name:s: an option with an optional string value,
        • name=i: an option with a mandatory integer value,
        • name:i: an option with an optional integer value,
        • name=f: an option with a mandatory floating-point value,
        • name:f: an option with an optional floating-point value,
        • name=b: an option with a mandatory boolean value,
        • name:b: an option with an optional boolean value,
        • name+: an option with an autoincremented integer value,
        • name!: an option which could be flaged or not: --name or --noname.
        Parameters:
        optionDefinitions - is the list of definitions of the available command line options.
      • hasOption

        @Pure
        public boolean hasOption​(String optionLabel)
        Replies if the given option is present on the command line.
        Parameters:
        optionLabel - is the name of the option
        Returns:
        true if the option is present, otherwise false
      • getFirstOptionValue

        @Pure
        public Object getFirstOptionValue​(String optionLabel)
        Replies the first value of the option.
        Parameters:
        optionLabel - is the name of the option
        Returns:
        the option value or null if the option is not present or has no value.
      • getOptionValues

        @Pure
        public List<Object> getOptionValues​(String optionLabel)
        Replies the values of the option.
        Parameters:
        optionLabel - is the name of the option
        Returns:
        the option values or null if the option is not present.
      • getParameters

        @Pure
        public String[] getParameters()
        Replies the parameters on the command line that are not options.
        Returns:
        the parameters.
      • shiftParameters

        public String shiftParameters()
        Shift the command line parameters by one on the left. The first parameter is removed from the list.
        Returns:
        the removed element or null
      • getParameterCount

        @Pure
        public int getParameterCount()
        Replies the count of parameters on the command line that are not options.
        Returns:
        the count of parameters
      • getParameterAt

        @Pure
        public String getParameterAt​(int index)
        Replies the parameter at the specified index.
        Parameters:
        index - position of the parameter to reply.
        Returns:
        the value of the parameter.
        Throws:
        IndexOutOfBoundsException - if the given index is out of bounds.
      • isParameterExists

        @Pure
        public boolean isParameterExists​(int index)
        Replies if the given index corresponds to a command line parameter.
        Parameters:
        index - position of the parameter to test.
        Returns:
        true if the given index corresponds to a parameter, otherwise false
        Throws:
        IndexOutOfBoundsException - if the given index is out of bounds.