-1

I tried to pass blank command line arguments in a Netbeans Java project using Properties-->Run-->Arguments with "" or '' but nothing. I have some arguments that some times have to be empty or null.

1 Answers1

2

The common way to handle that is to not specify arguments when they are blank or empty. It is quite the norm in the CLI/scripting world to work like this. Unspecified arguments mean either to use the defaults or no value.

Aside there are Java nice libraries to help you parse your program options or arguments, such as:


EDIT

Additonal remarks:

  • Without a smarter options/arguments parser, it is not possible to handle empty arguments properly (i.e. just by setting a blank, whitespace or quoted empty string). The only way to achieve that would be to define a keyword or special character in order to identify empty/unspecified arguments when processing args[].
  • This behavior is not bound to Netbeans. Rather it relates to how Java parses the varargs of the main() method from the command-line.

Interesting links:

bsaverino
  • 1,221
  • 9
  • 14
  • In netbeans args are separated by a blank character between them. So to not specify an argument must have two consecutive blank characters. I tried it. Nothing. – nonlinearly Aug 05 '20 at 15:33
  • You will need to use one the mentionned libraries to achieve that. Clearly if you are using rawly the args from the `main()` method, none of them can be null or empty. Without a clever parsing, you will not be able to achieve great things with your arguments or options. I strongly recommend you investigate the given links. It is extremely easy to use. – bsaverino Aug 05 '20 at 15:42
  • To say it differently: nothing (including blanks, whitespaces, quotes) will help you in dealing with empty/unspecified arguments. You have to work with well-formated options and common parsers, or define a constant for empty values (such as `NIL`) and compare given args against this constant to determine if the argument is legal/valid or should be treated as empty/unspecified. – bsaverino Aug 05 '20 at 15:55
  • 1
    @nonlinearly - I agree with bsaverino. It is well worth a small investment of time to use a command line parser, for this situation. – andrewJames Aug 05 '20 at 16:06
  • Also I'm so disappointed with SO... It makes such a big fuss about something so simple...Sometimes it gives me the impression that it wants the questions to have the answers. If so it makes no sense – nonlinearly Aug 06 '20 at 07:14
  • Not sure to understand what you mean, but yeah this is not a forum here. – bsaverino Aug 09 '20 at 02:05