Domanda

Consider a main method:

public static void main(String[] args) throws Exception {
    System.out.println("property='" +  System.getProperty("property") + "'");
    List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();
    System.out.println("jvm input args size: " + inputArgs.size());
    System.out.println("jvm input args: " + inputArgs);
} 

Results from running the program:

>java -Dproperty=hey!
property='hey!'
jvm input args size: 1
jvm input args: [-Dproperty=hey!]

>java -Dproperty="one two three"
property='one two three'
jvm input args size: 3 //but there's only one input property!
jvm input args: [-Dproperty=one, two, three] //!!!

At least that's the behavior on Oracle/Sun's jvm 6 on mac) & on win (haven't tested elsewhere).

Does anyone know a way of getting input args that is reliable when system properties contain spaces?

È stato utile?

Soluzione

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top