Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a file as command line argument in Netbeans

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

like image 421
Ushsa Varghese Avatar asked Feb 28 '12 04:02

Ushsa Varghese


People also ask

How use command prompt in NetBeans?

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.

How do you pass a command line argument?

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.


2 Answers

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

Run with Arguments plugin as shown in NetBeans IDE 8.0 plugins dialog box

like image 71
Tushar Joshi Avatar answered Nov 15 '22 07:11

Tushar Joshi


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 !

like image 22
Hugues Avatar answered Nov 15 '22 08:11

Hugues