Project-Level License Settings in NetBeans IDE 6.0

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:

    ${project.license}

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

    project.license=apache

    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.

Comments:

Thanks for that Geertjan :)

Posted by Roridge on November 26, 2007 at 05:45 AM PST #

please! improve the text aditor! please!

Posted by bruno on November 27, 2007 at 07:43 PM PST #

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:
http://www.netbeans.org/community/issues.html

Posted by Geertjan on November 27, 2007 at 07:58 PM PST #

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...?

Posted by Bob on December 04, 2007 at 01:34 AM PST #

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.

Posted by Geertjan on December 04, 2007 at 01:38 AM PST #

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.

Posted by Son Ying on December 12, 2007 at 05:40 AM PST #

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.

Posted by Geertjan on December 12, 2007 at 05:46 AM PST #

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

Posted by Duncan on January 08, 2008 at 08:24 PM PST #

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?

Posted by John Resler on January 10, 2008 at 08:13 AM PST #

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

Posted by Geertjan on January 10, 2008 at 09:27 AM PST #

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...

Posted by Goran Ehrsson on January 12, 2008 at 07:51 AM PST #

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

Posted by Henry Jen on February 06, 2008 at 03:31 AM PST #

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.

Thanks.

Posted by Tom Mueller on March 24, 2008 at 02:57 AM PDT #

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..

Posted by Tiago Antao on April 03, 2008 at 05:12 AM PDT #

For setting the project license template to use with a Maven project in Netbeans see:
http://mevenide.codehaus.org/m2-site/mevenide2-netbeans/customizations.html

Posted by Michael Bedward on May 12, 2008 at 02:19 PM PDT #

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.

Posted by Trejkaz on March 13, 2009 at 09:42 AM PDT #

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

Posted by Geertjan on March 13, 2009 at 09:48 AM PDT #

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.

Posted by Geertjan on March 13, 2009 at 10:23 AM PDT #

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.

Posted by Chuck Kingsley on March 13, 2009 at 10:25 AM PDT #

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.

Posted by Fred on March 13, 2009 at 10:27 AM PDT #

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.

Posted by Trejkaz on March 13, 2009 at 10:06 PM PDT #

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.

Posted by Tiago Adami on August 01, 2009 at 04:04 AM PDT #

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?

Posted by Dave on August 20, 2009 at 01:25 PM PDT #

I just figured it out thanks to Michael Bedward.

Posted by Dave on August 20, 2009 at 01:34 PM PDT #

hello,
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...)

Posted by stephane on October 25, 2009 at 03:31 AM PDT #

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.

Posted by Ken Lareau on November 03, 2009 at 03:16 PM PST #

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.

Posted by Geertjan Wielenga on November 03, 2009 at 05:39 PM PST #

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.

Posted by levancho on December 06, 2009 at 01:05 AM PST #

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.

Posted by Mike McLin on December 23, 2009 at 12:38 AM PST #

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.

Posted by immeëmosol on December 30, 2009 at 02:29 AM PST #

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.

Posted by guest on June 07, 2010 at 11:00 PM PDT #

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

Posted by Alex on August 15, 2010 at 04:17 AM PDT #

Really helpful! thank you very much, I was just wondering how to do it with Maven also in Netbeans

Posted by Acdel on June 05, 2011 at 11:06 PM PDT #

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

<netbeans.hint.license>apache20</netbeans.hint.license>

By the way, this is the only article I ever found actually adressering this properly, and it even works in NB 7:
http://explodingjava.blogspot.com/2010/03/gpl-license-java-project.html

Posted by Torsten on July 16, 2011 at 04:44 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today