X

Geertjan's Blog

  • June 20, 2005

Provide Runtime Arguments for Selected Class Files in NetBeans IDE 4.1

Geertjan Wielenga
Product Manager
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.

Join the discussion

Comments ( 3 )
  • ggg Tuesday, November 8, 2005
    ggggg
  • guest Wednesday, March 1, 2006
    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
  • Geertjan Friday, March 3, 2006
    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.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha