how to get the command line arguments from another class with java

后端 未结 5 782
栀梦
栀梦 2020-12-18 22:18

so suppose I have a java package....

it\'s got the main class with the main method

and then it\'s got a whole bunch of other classes.....

my question

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 23:15

    The system-properties on some (?) JRE-implementations provide the system-property "sun.java.command" to get the programm-name and parameters that were used to start the program. Like "myjar.jar param1 param2 ...".

    While this value doesn't even belong to the set of properties that are mentioned in the documentation, it is present in both Oracle-JRE v1.8 and OpenJRE v1.8 (tested).

    I couldn't find any documentation whether this value is supported by default though (best I could find was the list in the System#getProperties() docs). Any clarification on this would be welcome. Handle with care!!!

提交回复
热议问题