Geertjan's Blog

  • November 26, 2007

Project-Level License Settings in NetBeans IDE 6.0

Geertjan Wielenga
Product Manager
In my earlier series on FreeMarker support (especially this one), I discussed the many flexible ways in which templating support in NetBeans IDE 6.0 can be of benefit to you. Importantly, the flexibility can be made use of either by the developer providing the templates or by the user of those templates. (That series discusses this, and the differences, in some detail.) One point that I hadn't discussed yet relates to licensing. The short story is: in NetBeans IDE 6.0 you can define a license for your project and then all files within that project will be created with that license embedded in the code. OK, that's the short story.

The long story makes sense in the context of a step-by-step procedure:

  1. Go to the Tools menu. Choose Templates. Open the Java|Java Class template in the editor:

  2. In general, the template above, and the ramifications of defining it in FreeMarker, have been discussed in the earlier blog entries (starting here). However, lets look (this time) at the first four lines:

    <#assign licenseFirst = "/\*">
    <#assign licensePrefix = " \* ">
    <#assign licenseLast = " \*/">
    <#include "../Licenses/license-${project.license}.txt">

    What do these lines mean? They all have to do with licensing. The last line determines the license that will be used, per project. The first three determine the characters in front of and behind each line in the license. Above are the four lines for Java source files. Here's the same set of definitions you'll find for the Properties file template:

    <#assign licensePrefix = "# ">
    <#include "../Licenses/license-${project.license}.txt">

    What's the difference? Nothing in the second line (which we'll look at later). The first line, however, tells us that each line in the license will be prefixed with a "# ", instead of with a " \* ", which is the prefix for Java source files (with "/\*" for the first line and " \*/" for the last line). To verify this, create a Java source file and then create a Properties file. You'll see a license in both cases. However, the characters prefixing and postfixing each line is different. Now you know why.

  3. Next, let's look at the license itself. Notice this line in the templates above:

    <#include "../Licenses/license-${project.license}.txt">

    In particular, notice this bit:


    Put that, as a key, in your application's nbproject/project.properties file. Now add a value. For example:


    Now look in the Template Manager again, in the Licenses folder. You see some templates there. Create a new one called "license-apache.txt". For now, you can just copy an existing one and paste it in the same category in the Template Manager. Then, next time that you create a file that is defined by a FreeMarker template that includes this line:

    <#include "../Licenses/license-${project.license}.txt">

    ...you will have the specified license embedded within the newly created file.

What's the purpose of all this? Simple: NetBeans IDE 6.0 lets you define, per project, the license that each of its files should display. Plus, imagine if you need to create a new project with a different license. Assuming you have all your licenses defined in the Template Manager, using a new license is as simple as adding that one key/value pair to the nbproject/project.properties file. That was not possible before but, thanks to FreeMarker support in NetBeans IDE 6.0, is possible now.

Join the discussion

Comments ( 34 )
  • Roridge Monday, November 26, 2007

    Thanks for that Geertjan :)

  • bruno Wednesday, November 28, 2007

    please! improve the text aditor! please!

  • Geertjan Wednesday, November 28, 2007

    What are you talking about, Bruno? "Improve the text editor" is really not enough information to be able to do anything with it. Also, this is the correct place to file enhancement requests, if that is what you're trying to do:


  • Bob Tuesday, December 4, 2007

    Just tried this in NB6 final on an existing prohject with its own Ant build script and it doesn't appear to work? There was no project.properties file in the nbproject folder, so I created one, but I'm still getting the default license text.

    How is this supposed to work for projects with their own Ant build scripts...?

  • Geertjan Tuesday, December 4, 2007

    Hi Bob, I haven't tried this with projects that have their own Ant script. I'm not sure if/how it would work there, but I will try and find out. Also, you can write to nbusers@netbeans.org about this. Thanks for your question. Once I have the answer I will blog about it.

  • Son Ying Wednesday, December 12, 2007

    I'd really like to know why non of this is mentioned in the documents coming with NB6.

    Templates (__TIME__, __DATE__, ...) weren't documented in 5.x, and now the new templates aren't documented in NB6. See a pattern?

    It just took me two hours to convert my old templates to NB6, and things like ${application.title} in a template still don't work :-( That new template system you seem to be so proud of is royally broken.

  • Geertjan Wednesday, December 12, 2007

    I'd like to help, but you've given no description at all of what is going wrong. Feel free to write to me at geertjan DOT wielenga AT sun DOT com.

  • Duncan Wednesday, January 9, 2008

    for ant projects, can also specify in project.xml using <project-license> element under <general-data>

  • John Resler Thursday, January 10, 2008

    Geertjan, the problem I'm running into is that modifications to the project.properties file result in the following code insertion in my classes from templates:

    Error reading included file Templates/Classes/../Licenses/license-apache.txt

    As I cannot find the directory Templates/Classes.. I suspect I need to put a license-apache.txt file there but I'm wondering if this is inside a nbm file and therefore not easily found? Got any advice?

  • Geertjan Thursday, January 10, 2008

    John, look in the Template Manager under the Tools menu.

  • Goran Ehrsson Saturday, January 12, 2008

    If I put project.license=mylicense in project.properties and create a license file, the template stuff works. The correct license text is inserted in my source files.

    But I get a Resolve Reference Problems message that says that the project 'license' cannot be found.

    This happen on one of my projects, not all of them. And I cannot find a difference. Very strange...

  • Henry Jen Wednesday, February 6, 2008

    I have the same issue with Goran, and seems like different type of project is taking different approach[1] for specifying this property.

    Should there be a consistent way for specifying this property?

    [1] http://www.netbeans.org/issues/show_bug.cgi?id=115058

  • Tom Mueller Monday, March 24, 2008

    What is the syntax of the <project-license> tag in the project.xml file? I haven't been able to find any documentation on that.


  • Tiago Antao Thursday, April 3, 2008

    I also have the precise same problem reported here with ${application.title} i.e. I get:

    Expression application is undefined on line 4, column 28 in Templates/Licenses/license-default.txt..

  • Michael Bedward Monday, May 12, 2008

    For setting the project license template to use with a Maven project in Netbeans see:


  • Trejkaz Friday, March 13, 2009

    This is not working.

    I created a template called GPL3 under Tools/Templates. I then created nbproject/project.properties and put project.license = GPL3... didn't work. Projects still got the default license.

    Then I tried putting it in the XML. I tried <project-license> under <general-data>. I tried <license> as well, as I noticed <name> wasn't <project-name>. I tried variations using "licence" instead of "license", in case someone had made it English instead of American. I tried putting it under the <properties> element too but I don't really know the syntax because it is empty to start with, so this may have worked if I knew how.

    Really it wouldn't hurt to document these things, guys. If you're not going to have UI for setting such a vital variable, at least make the file format simple enough to edit, and make it the properties format. Or give us something like project-level templates, so that we don't have to fool around with variables and crap which don't work.

    I think it's time to give up on this and go register for an open source developer licence for IDEA. There is only so much development time one can waste trying to make an IDE not screw up.

  • Geertjan Friday, March 13, 2009

    Would like to help you, but please write to nbusers@netbeans.org where more people will be able to do so.

  • Geertjan Friday, March 13, 2009

    By the way, seems to me that your license file should be named "license-GPL3.txt", based on the text in this blog entry. I just tried that and it works. Why not follow the instructions as described here? Really it wouldn't hurt to follow the instructions guy.

  • Chuck Kingsley Friday, March 13, 2009

    Trejkaz, putting the license under Tools/Templates is wrong too. Really, read this blog entry a few more times. I did, I followed the instructions, and everything works.

  • Fred Friday, March 13, 2009

    But maybe it's time for him to go and join IDEA, good luck getting info on this in IDEA, Trejkaz. Their docs totally suck and they have no bloggers that describe as much stuff as is done in this one single blog by one single person.

  • Trejkaz Saturday, March 14, 2009

    Turns out to have been not so painful in IDEA, actually. Project Settings, create a Copyright Profile, copy the boilerplate text into there, Source | Update Copyrights, done. I didn't even need to search help, let alone search the net for an hour.

  • Tiago Adami Saturday, August 1, 2009

    Why did not Netbeans use a Project License organizer like in eclipse?

    The actual template manager is very complicated, and I still having the message

    "Error reading included file Templates/Classes". And yes, I read this tutorial a few times.

  • Dave Thursday, August 20, 2009

    I'm trying to get this working with a Maven webapp project, and I can't seem to find a nbproject directory.

    Does anyone have any idea how I can get this working in a Maven Webapp project?

  • Dave Thursday, August 20, 2009

    I just figured it out thanks to Michael Bedward.

  • stephane Sunday, October 25, 2009


    I try to use NB6.7.1 on winXP for the first time and I try changing this "header comment" on php template since two hours without success...

    I have read this blog xxxx times and do all xxx times without success....

    I edited the project.properties file, put "project.license=spi", then I go to "tools->templates", under the "licenses" folder there was a "default license", I tried to "copy" it then rename it "license-spi.txt" (or "license-spi"... I tried to create a file called license-spi.txt and add it with the button "add" (under tools->templates"... without success...

    is there really a way to have this work ?

    thanks for your help (and scuse for my bad english, i am french...)

  • Ken Lareau Tuesday, November 3, 2009

    I've found that the above instructions pretty much don't work either with Netbeans 6.7.1; no matter what project.license is set to in the project.properties file, the default license is always used. It's also nice that the mailing list archives are unavailable and forum.netbeans.org isn't allowing new user accounts so I can't even post my issues.

  • Geertjan Wielenga Wednesday, November 4, 2009

    Just tried it, Ken, in 6.7.1. It works fine. Your problem is, probably, that you're looking at the display name of the license, rather than the file name. Try this: in the Template Manager, right-click your license file, choose Properties, and look at the "File Name" property. You should probably change that to the actual file name of the license, because it probably still has the same name as the original license file that you copied.

    Secondly, you couldn't find the mailing lists and whatever else because the site is under maintenance this week. Thirdly, next time you leave a sarcastic comment in my blog, which I work on in my free time and only to do people like you a favor, I will not publish it in my blog.

  • levancho Sunday, December 6, 2009

    I found a simple workaround, based on suggestion above,

    just change license templates "file name" to match its "display name" (minus file extension) from your license file properties dialog.

  • Mike McLin Wednesday, December 23, 2009

    I'm having issues as well. I am using version 6.7.1. I have gone over the tutorial a million times. I have posted my issue on StackOverflow. Here is the link: http://stackoverflow.com/questions/1953713/project-specific-licenses-in-netbeans-using-file-templates.

  • imme&euml;mosol Wednesday, December 30, 2009

    Hey Geert-Jan,

    is het misschien mogelijk om het blogbericht aan te passen zodat het verhaal over "met de rechter muisknop klikken" daar óók staat?

    (comment: http://blogs.sun.com/geertjan/entry/project_level_license_settings_in#comment-1257327558000 )

    Het heeft mij in ieder geval goed geholpen

    maar ik had het sneller kunnen vinden wanneer het in het blogbericht had gestaan.

  • guest Tuesday, June 8, 2010

    One might want to add “<#if project.license?? && project.license != "default">” in front of the license section and “</#if>” after it. This shows the license text only if a license is set for the project.

  • Alex Sunday, August 15, 2010

    The work around is simple. Problem happens because file name is not property created. The problem is fixed in NetBeans 6.9.1

    Either update to latest NetBeans or follow this tutorial [http://boolcast.com/lamp/php/10-netbeans-custom-project-license] on how to make Project Specific licenses

  • Acdel Monday, June 6, 2011
    Really helpful! thank you very much, I was just wondering how to do it with Maven also in Netbeans
  • Torsten Saturday, July 16, 2011

    For Maven, put a netbeans.hint.license property in your POM with the appropiate value, e.g. for license-apache20.txt:


    By the way, this is the only article I ever found actually adressering this properly, and it even works in NB 7:


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.