Determining NetBeans project configuration from Ant

NetBeans allows you to define projects configurations (e.g. debug, release, live, dev, whatever), so you can easily switch things like your Main class and arguments and arguments to the JVM. I typically use at least a ‘Dev’, ‘Staging’ and ‘Live’ configs.

Now I am customising my NetBeans builds, I need to determine what config the project is in. There was zero documentation on this, but it was easy to figure out:

  • NetBeans stores your configs in {Project.Root}/nbproject/configs (you will see a properties file for each config)
  • The currently set config is stored in {Project.Root}/nbproject/private/config.properties, which simply has one property called config.

So determine this in your build script, simply use Ant to import the config.properties file:

<property file="nbproject/private/config.properties"/>

Thats it! You can then read your project configuration using ${config}. E.g:

<if>
    <equals arg1="${config}" arg2="Publish" />
    <then>
        ... do some stuff	
    </then>
</if>

posted 2 years ago