The only way to get to the command line arguments in a plain Java program is the main
entry method. Neither java.lang.System
nor java.lang.Runtime
have methods to access the args.
There is a
-Dkey=value
subset of command-line args, which JDK parses and interprets as "system properties", and there is indeed API to get these. For the regular program args there is however no such API whatsoever.There is a spurious
sun.java.command
system property, which works in plain Java but does not seem to work in a running Equinox (tried with Oracle JDK 1.8.0_31). S. this topic Is it possible to get the command used to launch the jvm in java?In Equinox they introduced the
EnvironmentInfo
service, which provides such API, but its implementation is weird (mix of an OSGi service and public-static) and buggy in the way that the service is very dependent on the way OSGi Framework Launcher initializes it. We have used it till recent, but now ran into a very unpleasant issue where the service is there but is not yet statically initialized by the (BND) launcher.
Why there is no any standard mean to access the command line args in Java in a static way from anywhere in the code? Is it a JDK design flaw or was there some intentional thought behind it?