Answer the question
In order to leave comments, you need to log in
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.
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
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]);
}
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 questionAsk a Question
731 491 924 answers to any question