Showing posts with label Coding Practice. Show all posts
Showing posts with label Coding Practice. Show all posts

12 February, 2018

How to add copyright to Eclipse

How to add @copyright to your code in eclipse ?

As a developer , we mostly want to reduce few development or coding effort while working on a project. Adding @copyright to your java file or your project file is quite easy. There are few ways you can achieve these. 

First Solution :- You can use 3rd party plugin to generate the @copyright. Follow the steps to install the plugin and add copyright for your project.

 1. Go to => Help => Eclipse MarketPlace => Search for copyright generator



2. Click on => Install and proceed further for finishing the installation. After the plugin installed successfully.
3. Go to menu => Project => Apply Copyright 


4. Now , Select custom copyright and paste your copyright header text in the text area. I have used the below sample header for my blogging.


/*******************************************************************************
 * Java Developers Guide Blogging - Confidential
 * ____________________
 *
 * [2018] - [2019]  Java Developers Guide Incorporated
 * All Rights Reserved.
 * 
 * NOTICE:  All information contained herein is, and remains
 * the property of  Java Developers Guide Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to  Java Developers Guide Incorporated
 * and its posts and articles are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Java Developers Guide Blogging.
 *
 * Generated on Feb 12, 2018
 ******************************************************************************/

Then , apply the included or excluded as per your need. I have added the included in this example. That means here I want to add copyright header text for all java file (i.e. *.java).  This expression will to add all .java files. Sample image below.



 5. Next => select the project you want to apply => Then select the java files you want to apply 


6. Now you can see the java files with your header copyright text as below.




Second Solution :-


You can directly add the header copyright text into the {template} in eclipse IDE. Follow the steps below.

1. Go to => Windows => Preferences => Java => Code Style = > Code Templates => Code

Then select "New Java files" , then add your copyrights in the first line as mentioned in the image below. Then Apply and finish.




2. Now create a new file ( Go to = File => New => Java Class)



Now you can see the copyrights has been added to your java classes. Hope it will help you to improve the coding practice and coding standards.


Hope it will help you.




28 January, 2018

How to add formatter in eclipse

How to add my own or your company specified code formatter into eclipse ? 


Everyday we are facing lots of issues with development environment and its quite genuine. I though to share this steps also to help you to format your code with best practice. Usually, we need to develop a clean, and most readable code. You can add your own formatter into eclipse IDE (I am using Eclipse Mars in my example). But, You can use any other eclipse release version.

Normally we use the formatter with .xml file format. Its, nothing but a set of rules defined in XML. It defines how your code should look like as a structure.

1. Go to ==> Windows ==> Preference 

The below screen will appear.




2. Select ==> Java ==> Code Style ==> Formatter

The below screen will appear.




3. Now click on ==> Import button to import your formatter xml .

 The below screen will appear.




Now you can see the active formatter in eclipse, please see the below image with highlighted area.



The above image shows your selected formatter, now you are ready to do the code formatting as per your defined rule in the formatter xml , that you have just now imported. Now, you can  see the active profile as your formatter. You can use your keyboard shortcut key (Ctrl+Shift+F) for format the code or you can use the code format option from menu options.

In my next post I will post how to define the rules for write your own formatter. So, please keep following me.



Hope it will help you.