I’m curious to know if it is possible to determine the startup arguments of a Java application when you don’t have access to the arguments array from the main line.
public static void main(String[] args)
{
// Invokes my code without providing arguments.
mycode();
}
public static void mycode()
{
// Attempting to determine arguments here.
// TODO GetArgs()
}
I’m in this situation by doing some plugin work and the core application does not provide a list of startup arguments. Any thoughts?
Not unless the plugin is given them, but that kind of goes without saying (at least in Java).
If you need to set some options specifically for your plugin, but can’t access the command line, there are at least two options:
For the second option, just use the normal
-Doption and namespace the param name, like:Retrieve them via
System.getProperty(anOptionName)or one of its cousins.IMO an options file is a better (ahem) option, even if you’re specifying the file path on the command line, but if you only have an option or two, maybe not–just depends.