In programming, copyright license is usually put at the beginning of every source file. This article shows you how to manage copyright license with ease in Eclipse. You will be able to generate (and update or rewrite whenever you want) a nice copyright license like the following screenshot:

Copyright License Example

There are two different ways to add/update copyright license to Java source files. We look at the simplest way first.

 

1. Modifying Java Code Templates

In this way, we use a built-in feature of Eclipse. Click Window > Preferences to launch the Preferences dialog. Then expand the tree on the left to the branch Java > Code Style > Code Templates:

Edit Code Template for New Java File

Then expand the branch Code > New Javafiles under the section ‘Configure generated code and comments’. We are going to modify code template of every new Java file created afterward, so click Edit button. In the Edit Template dialog, insert some sentences for your copyright license into the Pattern text area:

Edit Template Pattern

NOTE: You can insert some predefined variables by using the button Insert Variable.



Click OK when you are done editing. Then we get back to the Preferences dialog with the newly updated pattern:

Code Templates Updated

From now on, Eclipse will insert the above copyright license into every new Java file you created afterward.

But what if you already have dozens of files in your project and you want to update the copyright statements for all these files? Search and replace the entire project maybe a good choice, but it’s not the best. Let’s move on the second way to explore the best solution.

 

2. Using Eclipse’s Releng Tools

Eclipse has a very nice tool called Releng which is intended to solve all headaches regarding copyright license update in Java projects. Releng has a unique function called “Fix Copyrights” which is very useful. Because Eclipse doesn’t include this tool by default, so we have to install it.

Go to Help > Install New Software… to open the Install dialog:

Select Eclipse Update Site

Select “The Eclipse Project Updates - http://download.eclipse.org/eclipse/update/4.4” from the Work with dropdown list. The number is different depending on your Eclipse version, here I use Luna, hence the number 4.4.

Eclipse then lists all updates in the below table. Scroll down to the bottom of the list, check Releng Tools and click Next.

The next screen is for review purpose:

Review Releng tools

Click Next to proceed to the Review Licenses screen:

Accept License

Choose “I accept the terms of the license agreement” then click Finish. Wait a while for Eclipse to install the RelengTools:

Install in progress

After the installation completed, you have to re-start Eclipse when asked:

Ask to Restart

Now go to Window > Preferences, and select Copyright Tool:

Copyright Tool default setting

You can see there is a default copyright template, edit the template as you want and then click OK to save changes. Here what we typed:

CodeJava copyright template

NOTE: You should check the option “Replace all existing copyright comments with this copyright template” so Eclipse will re-write copyright statements in all files.

Now we can use the Fix Copyrights context menu to apply copyright template to the whole project, a package or a single source file:

Fix Copyright context menu

Notice Eclipse reports status of update in the Console view as shown in the following screenshot:

Fix Copyrights Status

NOTE: Our test shows that the Releng Tools only works with projects shared using Git repository. If your project doesn’t have source control like Git, it doesn’t work.

 

Conclusion:

So far we have explored the two ways of generate and updating copyright license for source files in Eclipse. The modification of code templates is quick and easy but limited. And the Releng Tools is the ultimate solution which is more powerful and flexible. But one limitation of Releng is that it works with Git-based projects only. Hope Eclipse will make it to works with all projects soon.

 

References:

 

Other Eclipse Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment

   


Comments 

#1Kaushal Kumar2014-12-08 04:40
The Note should have been placed at the top.

NOTE: Our test shows that the Releng Tools only works with projects shared using Git repository. If your project doesn’t have source control like Git, it doesn’t work.
Quote