Support for Variables in NetBeans projects aka IDE Variables.
IDE Variables is simple concept of using paths which are based on a variable. Let me illustrate it on example. Let's say you have jar library (in Maven repository in this example)
which you want to add to classpath of your HelloWorld project:
In NB6.1 you have couple of options how to reference the file:
- reference it via absolute path - main disadvatange of this approach is that such a project will not be sharable with other users
- reference it via relative path - such a project will be sharable with other users if and only if all team members have the same directory structure
- copy jar file to Libraries Folder and reference it relatively - not an option if user cannot or just do not want to copy file
With IDE Variable user can define a variable in IDE's usedir:
MAVEN_REPOSITORY_ROOT = /home/david/.m2/repository/
and reference the jar from HelloWorld project via variable based path:
This is very common way how to setup your project in sharable manner.
Why to implement this features?
- numerous times requested by users (mailing lists; issue zilla)
- there are legacy project setups which cannot reference files any other way
- library repositories like Maven are very common these days and using IDE variables is easiest way to access them
- both Eclipse and IntelliJ supports this
- Ant supports this as well - it is just NB UI which disallow that and clobber hand written customization
- makes it easier to import Eclipse projects which using varaibles to NB (from sample of 800 random eclipse projects 250 of them used variables in .classpath file)
I did prototype this feature in half a day and would need half a day to tidy it up.
For discussion start here is UI from my prototype:
In Tools menu there is new action Variables which shows (similarly to Libraries or Platforms) customizer for variables:
It is list of variable names and locations there point to; they are sorted alphabetically (oops not in screenshot); you can edit/add/remove them. Variables are stored in build.properties in user directory and in properties file they are prefixed with "var." similarly as libraries are prefixed with "libs."
Project Properties customizer recognize variable on project classpath and shows it correctly:
Variable based JAR/Folder is added to classpath via standard "Add JAR/Folder" button and shows custom file chooser enhanced for handling variables:
If JAR/Folder selected is under a variable root then option "Use Relative Path to Variable" is enabled and shows non-editable preview how the JAR/Folder will be referenced. Button "..." opens variables manager.
If project is opened and variable is missing then standard broken references dialog is shown:
and Resolve button shows Manage Variables dialog where user can add variable.