I have trying to work out with Netbeans for the last two days. I am writing a scanner program that takes input of the scanner from a file token_list.java. So How can we give this token_list.java as an argument to the Main file ( Scanner.java). When I am doing it on the Unix system using command line argument all works fine and well. The problem comes when i am doing it on netbeans. I have even tried giving the file name token_list.java as an argument in the run properties in the project. But then later i realized that the command line arguments for the run properties are for just giving the inputs rather than the file name.
Update : The command that I give in unix is $java Scanner input.text So What I am now trying to do in netbeans is right click on the scanner.java and run it. But it then gives the error that no arguments have been passed. I am taking the file name in argv
Right-click (on Windows) or Control-Click (on a Mac) the project branch in the NetBeans Projects pane. In the resulting context menu, select Properties. As a result, the Project Properties dialog box opens. On the left side of the Project Properties dialog box, select Run.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.
There is a community contributed plugin named NbRunWithArgs https://github.com/tusharvjoshi/nbrunwithargs which will provide you "Run with Arguments" option when you run Java project or a single Java file.
You may want to use this plugin, more details are available on blog post here.
UPDATE (24 mar 2014) This plugin is now available in NetBeans Plugin Portal that means it can be installed from Plugins dialog box from the available plugins shown from community contributed plugins, in NetBeans IDE 8.0
In Netbeans, right-click on your Project name and click Properties In the "Run", you can define, which class is the main-class, the working directory and arguments After that, try to run the project, not the class itself !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With