-1

I am coding this below functionality where I need to run a class which takes some parameters this will perform an action on the server that is given in the url ....

oracle.ucm.client.DownloadTool --ping --URL=abz.com --param1=abc --param=xyz

And this class is present in a jar which I have included in the build path.

Executing this manually through command line looks something like this:

bash$ java -classpath ".jar file location" abc.xyz.DownloadTool --ping --url=www.google.com --username=xyx --password=abc

Please let me know how to program this.

Mihail Duchev
  • 4,691
  • 10
  • 25
  • 32
  • are you looking for something like this? https://stackoverflow.com/questions/367706/how-do-i-parse-command-line-arguments-in-java – Anurag Wagh Jun 16 '20 at 05:35

1 Answers1

0

Convert your JAR file to executable. Executable name can be "ucmclient". Ref: https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable

ucmclient oracle.ucm.client.DownloadTool --ping --URL=abz.com --param1=abc --param=xyz

In your main class:

Retrieve class name from command line arguments:

String className = args[0];

Create object of class using class name, You can use any of below option:

  • Use switch case
    switch(className)
    {
        case "oracle.ucm.client.DownloadTool" 
            oracle.ucm.client.DownloadTool downloadTool = new oracle.ucm.client.DownloadTool();
            downloadTool.main(args);
    }
  • You can use Reflection.
  • You can also use factory design pattern.
pcsutar
  • 1,715
  • 2
  • 9
  • 14