'Passing the asterisk as command line argument to main in Eclipse

I'm working on a Java project in Eclipse and now I'd like to pass the asterisk * as a command line argument to the main. I'm aware of the fact that this is a wildcard symbol and in every shell it works fine by simply putting it into quotes, so instead of java MyProgram * I'd type java MyProgram "*".

In Eclipse (Run Cofigurations -> Arguments) it doesn't work either way, even with quotes it just lists all files inside the directory. Single quotes as in '*' works the same way as a*a or something, meaning the single quotes (or apostrophes) will be passed into the string, too.

Any ideas how to get the * into the main?



Solution 1:[1]

Eclipse expands the * into a list of property names. So the program is actually passed (on my system) an args array of: .classpath, .project, .settings, .bin, .src Instead of the * .

If I put ANY text with the , like "X", then I get the "X*".

Doubles quotes does not help. Neither does escaping it with a slash.

From the shell it works fine, although a warning on Windows at least that you do need to put it in quotes. Windows will strip the quotes before the program gets it.

But under Eclipse, I can find no workaround that allows passing just a * .

Solution 2:[2]

To anyone running into the same problem, you need to write it as "* " for eclipse to pass it as *

Solution 3:[3]

It's a programming bug in your own program. Eclipse passes the main arguments verbatim to your program. You can easily check this by creating a Java program which has only this one line in main:

System.out.println(args[0]);

and passing an asterisk as the only argument to that program in the run configuration. That prints the single asterisk character, as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dave
Solution 2 Fabi
Solution 3 Bananeweizen