[java] how to pass command line arguments to main method dynamically

I am passing my main class as a command line argument to launch VM

Now i need to pass command line arguments to that main class

Is there any way to do this?

this is the way i am doing it

    VirtualMachineManager manager = Bootstrap.virtualMachineManager();
    LaunchingConnector connector = manager.defaultConnector();
    Map arguments = connector.defaultArguments();
    ((Connector.Argument)arguments.get("options")).setValue(userVMArgs);
    ((Connector.Argument)arguments.get("main")).setValue(cmdLine);

here userVMargs is classpath of my main class and the also classpath of the class which is being used to invoke the method of class inside my main class

and cmdLine is having my main class along with the class and its function and i am using eclipse as IDE to develop my project

This question is related to java eclipse

The answer is


Run ---> Debug Configuration ---> YourConfiguration ---> Arguments tab

enter image description here


go to Run Configuration and in argument tab you can write your argument


We can pass string value to main method as argument without using commandline argument concept in java through Netbean

 package MainClass;
 import java.util.Scanner;
 public class CmdLineArgDemo {

static{
 Scanner readData = new Scanner(System.in);   
 System.out.println("Enter any string :");
 String str = readData.nextLine();
 String [] str1 = str.split(" ");
 // System.out.println(str1.length);
 CmdLineArgDemo.main(str1);
}  

   public static void main(String [] args){
      for(int i = 0 ; i<args.length;i++) {
        System.out.print(args[i]+" ");
      }
    }
  }

Output

Enter any string : 
Coders invent Digital World 
Coders invent Digital World