Would like to make anapplication in Java that will not automatically parse parameters used on the command-line. Currently, java requires public static void main(string[]) as the entry point signature. I would like just a single string that I parse myself. Can this be done at all?
Here’s an example:
java MyProgram Hello World
I would want it to give me Hello World without requiring quotes around that string. I would even settle for java giving me the entire java MyProgram Hello World. I’m thinking this is something beyond Java and has more to do with the shell.
You’re correct about the shell part. Assuming you’re on Unix, your Unix shell will split your input string on whitespace and then hand you back each piece as an element in the array that is input to “main”. The only way to get everything in as a single string is to quote it like this (which you said you didn’t want):
java MyProgram 'Hello World'If you don’t want to do that, the easiest thing to do is just recombine them into a string:
The real problem here is that if you try to avoid quoting and you recombine the input strings yourself, you’re going to lose the amount of whitespace between each word. If you recombine, all of the following command lines:
will still just show up as “Hello World” inside your program.