Reputation: 576
Just wondering how to pass a String Array in the -D
command line argument in Java.
Essentially I wanted to pass 3/4 local paths as the command line arguments which can be used in the program. However, I'm wondering what is the best way to handle this, instead of passing each path as a -D
argument.
Thanks in advance.
Upvotes: 3
Views: 7993
Reputation: 16060
Using -D
defines parameters for the VM, to be obtained via System.getProperty()
whereas command-line parameters are usually understood to be those passed to public static void main( String[] argv )
.
Having said that, you could simply pass all your paths as command line arguments and use them in main
as indicated below:
java YourClass path1 path2 path3 etc.
where YourClass
contains
public static void main( String[] argv ) {
for (String path : argv ) { /* do something with this 'path' */ }
}
Cheers,
Upvotes: 6
Reputation: 5028
An important thing to say, that when you're using Eclipse (or any other IDE), you can send arguments using the IDE itself.
In Eclipse:
Run As -> Run Configurations...
or: Debug As -> Debug
Configurations...
Arguments
tab This way you can check your code without creating any jars.
Upvotes: 4
Reputation: 1712
pass your arguments like this
java yourprogram arg1 arg2 arg3 ... argn
these get passed on to your main
method, which you can use in your program:
public static void main(String[] args){
//use agrs here
}
Upvotes: 3