Download NetBeans!

20050620 Monday June 20, 2005

Provide Runtime Arguments for Selected Class Files in NetBeans IDE 4.1

In the Project Properties dialog box, the Arguments field specifies the runtime argument(s) for the main class. But what if you're not running a main class? How do you specify a runtime argument? The Project Properties dialog box doesn't support this scenario. But... Ant does! You can use Ant to create the application.args property which is used by the IDE when a file is run. However, you must make sure that the property is created at the right time -- before the project's properties are initialized. After the properties are initialized, you can't create the property again (you could override it in Ant, I guess, although I don't know how to do that yet). So, here's the target:

<target name="-pre-init" description="Set Runtime Arguments">
        
  <input message="Runtime arguments:"
       validargs="domsrc1.xml,domsrc2.xml,slide.xml,uddimsg.xml" 
     addproperty="application.args"/> 
       
</target>

Next, you need to go to the Project Properties dialog box and delete whatever class is specified as the main class. This means that when you run the project, you're prompted to select a new main class. That's a bit inconvenient, but not too bad. So, when you run the project, you select the new 'main class' and then the -pre-init target above is called -- this asks you what runtime argument you'd like to use. (You can specify any acceptable arguments in the Ant target above, of course. If you want a blank slate rather than a pre-defined set of options, just don't define the validargs property in the target.) Then the run target is called and the application is run using the argument that you selected.

Note, however, that the above scenario only works when you run the application, not when you run a file. In other words, when you right-click a file and choose Run File, the application.args is set, but somehow (not sure why, but probably because it sets application-level arguments, not file-level arguments) not used in the target that runs the file. So, you have to right-click the project and then choose Run Project for the desired effect to occur.

Jun 20 2005, 06:02:18 AM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/provide_runtime_arguments_for_selected
Comments:

ggggg

Posted by ggg on November 08, 2005 at 01:31 AM PST #

Shouldn't this just be supported by netbeans itself? It's now a bit of a pain to use and I need it often. Kees

Posted by 213.84.91.139 on March 01, 2006 at 02:04 AM PST #

Hi Kees, there's a plug-in module in my update center that covers this functionality. Yes, it should be supported out of the box, unfortunately it currently isn't.

Posted by Geertjan on March 03, 2006 at 12:54 AM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed