G
G
GrayIX2018-04-16 09:31:25
Java
GrayIX, 2018-04-16 09:31:25

How to perform different functions of a java program from shortcuts?

Hello. There is a slight need to run only certain functions of a java program, depending on the comment on the label (.lnk)
. something like - create several shortcuts to one program, on the desktop, with different data in the "Comment" field.
5ad4410feeca3056352062.jpeg
And in the program itself, you will need to find out in some miraculous way which shortcut it was launched from, perform a certain function. Actually, I want to know this wonderful way, if it is possible in principle. What java tools to use for this? Or maybe there is a better solution...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Kuzminov, 2018-04-16
@GrayIX

The arguments passed on the command line are used to pass certain information to the program when it is started. The arguments passed are stored as strings in the String array passed to the main method.

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

D
Dmitry Alexandrov, 2018-04-16
@jamakasi666

Although the answer has already been marked, but I will add a couple of other options.
1) lnk has a doc and specification which has a lot of interesting stuff. In fact, it's easier to open the shortcut with a notepad and you'll be surprised =) Ie. You can work with a label as with a regular text file.
2) java program can be run not only with arguments. You can make as many entry points as you like (classes with the main function) and call the desired type launch argument

java -cp MyJar.jar com.mycomp.myproj.MainClass2
. It may come in handy, for example, if you sell a program that can be run in the console version or with graphics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question