This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 174506 - Run File for any java file with main methods should accept command line parameters
Summary: Run File for any java file with main methods should accept command line param...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 6 votes (vote)
Assignee: Tomas Zezula
Keywords: PLAN
: 194372 202745 (view as bug list)
Depends on:
Reported: 2009-10-14 02:15 UTC by iceman81
Modified: 2013-07-03 20:39 UTC (History)
3 users (show)

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description iceman81 2009-10-14 02:15:05 UTC
Any java file in a project can be run using "Run File" but when the file is run it will not accept command line
parameters. For a project, the way to pass in command line arguments is to specify it in Run's Arguments under Project
properties. The issue is that when you use Run File for any file that is not the main class of the project it will
ignore the command line parameters. If you can use Run File on any Java file, we should have a mechanism to pass in
command line arguments. This seems to be a very obvious requirement.
Comment 1 Tomas Zezula 2009-10-14 09:42:16 UTC
Makes sense.
Not for NB 6.8 as the UI is already frozen, scheduled for next.
Comment 2 iceman81 2009-10-14 14:25:46 UTC
Understood. But, why would any Run File not read the arguments specified as part of the project's run settings? It seems
like all the pieces are there but just that some wiring is missing.
Comment 3 Tomas Zezula 2009-10-21 15:13:55 UTC
The problem is when you have more main classes in one project. You will pass the global args to all main files started by run single.
We can probably allow to specify args per file or at least when you start the class by run single and the class is also project main class the project args can be 
Comment 4 hantsy 2010-03-23 00:47:54 UTC
Why not provide a united run/debug/profile dialog to customize the action eclipse...
Comment 5 Tomas Zezula 2011-01-17 09:12:11 UTC
*** Bug 194372 has been marked as a duplicate of this bug. ***
Comment 6 Tomas Zezula 2011-09-29 07:03:53 UTC
*** Bug 202745 has been marked as a duplicate of this bug. ***
Comment 7 superole2 2012-01-17 16:47:50 UTC
I just managed to specify cmdline arguments pr class in NB7.0.1 using the following approach(I don't know where the magic happens, so bare with me):
1. I use maven (but again, I don't know if thats relevant).
2. I open the "Project Properties" dialog (right-click project -> Set Configuration -> Customize...).
3. I choose "Actions" in the Categories-tree (not "Run").
4. From the list of Actions I choose "Run file via main()".
I then get these values:
Execute Goals: process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec
Set Properties:
exec.args=-classpath %classpath ${packageClassName}

5. Now append to the exec.args line:  ${cl.args.${className}}
6. Add a new line with the cmdline arguments for a class with main():
cl.args.MyClass=-One -Two -Three
My "Set Properties:" field now looks like this:
exec.args=-classpath %classpath ${packageClassName} ${cl.args.${className}}
cl.args.MyClass=-One -Two -Three

7. click OK
8. right-click -> Run File
9. observe that args={"-One", "-Two", "-Three"}
Comment 8 cromat 2012-10-08 18:06:43 UTC
Has this even been looked at as something to enhance?
Comment 9 Tomas Zezula 2012-10-18 08:22:38 UTC
In fact the infrastructure already allows it. But there is no UI for it.
The question is how the UI should look like. Should be there an action set cmd line args on file. Or should be the user forced to create an configuration like in eclipse which is complicated and not very user friendly.
Comment 10 scooper4711 2012-12-13 22:52:13 UTC
For users switching from Eclipse (like me) this is a *huge* requirement.

While I'm glad that someone found and documented the very round-about way of getting command line arguments passed in, this needs to be fixed in order to be competitive with Eclipse.

A dialog similar to the "custom->goals..." for maven projects, with a "remember as" is all that's really needed.