Skip to main content

Insert the EUPL licence in your Java projects!

Insert the EUPL licence in yo…

Published on: 29/06/2009 News Archived

If you are developing a Java project you can include automatically the EUPL licence in your files with Netbeans 6.x.

This is possible because Netbeans allows you to define the structure of your java files. When you want to create a java file Netbeans asks you for example the name of the class and its package name. Name and package are parameters given to the template generator to create the new file but you can define other parameters like the licence.

If you go in the menu Tools -> Templates -> Java -> Java class and you click on Open in Editor you can see the following code:

 <#assign licenseFirst = "/*">

<#assign licensePrefix = " * ">

<#assign licenseLast = " */">

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

 

<#if package?? && package != "">

package ${package};

</#if>

/**

 *

 * @author ${user}

 */

public class ${name} {

}

As you can see the first part is dedicated to the licence while the second to declare the package and the class.

Concerning the licence, the first row will start with /* (using the licenseFirst parameter), each row will start with * (licensePrefix parameter), the last row will start with */ (licenseLast parameter). This is useful to include the licence as comment in the java code.

 

In particular, as you can note, there is a project.license parameter that you must set. To set this parameter you have to go in File windows and in nbproject folder you should find the project.properties

 

file. At the end of this file you have to add the following parameter:

project.license=EUPL

 

Now create a file on your Desktop or in a folder in your computer and put this content inside:

<#if licenseFirst??>

${licenseFirst}

</#if>

${licensePrefix}Copyright ${date?date?string("yyyy")} ${organization}

${licensePrefix}

${licensePrefix}Licensed under the EUPL, Version 1.1 or – as soon they

${licensePrefix}will be approved by the European Commission - subsequent 

${licensePrefix}versions of the EUPL (the "Licence");

${licensePrefix}You may not use this work except in compliance with the

${licensePrefix}Licence.

${licensePrefix}You may obtain a copy of the Licence at:

${licensePrefix}

${licensePrefix}http://www.osor.eu/eupl/european-union-public-licence-eupl-v.1.1

${licensePrefix}

${licensePrefix}Unless required by applicable law or agreed to in

${licensePrefix}writing, software distributed under the Licence is

${licensePrefix}distributed on an "AS IS" basis,

${licensePrefix}WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either

${licensePrefix}express or implied.

${licensePrefix}See the Licence for the specific language governing

${licensePrefix}permissions and limitations under the Licence.

<#if licenseLast??>

${licenseLast}

</#if>

and save the file with this name: license-EUPL.txt

 

Note 1: This code has been extracted from Guideline for users and developers EUPL Guideline

Note 2: The date variable is predefined in Netbeans, for more information see here.

Now go in the menu Tools -> Licenses and cliclk on the Add button to select the file you just created. As soon as you add it you will see in the list available licences.

Note 3: This file is saved in the system user folder inside the /.netbeans/6.1/config/Templates/Licenses folder.

As you can note, this file contains the organization variable; this variable must be defined in the menu Tools->Templates ->User Configuration Properties -> User.properties, adding for example:

organization=Unisys

Once finished to edit click on the save button to save this change.

Note 4: you can find this file in the system user folde inside the /.netbeans/6.1/config/Templates/Properties/User.properties

 

Now when you will create a new java class with Netbeans you will see the EUPL note in your code!

 

References

http://blogs.sun.com/geertjan/date/20071126

 

Login or create an account to comment.