I came across importing same stuff frequently. I thought of creating the shortcut for this.
Then I found eclipse is good in providing this kind of stuff.
The stuff I want to import are Logger from SLF4J, for this we have to import slf4j and lo4j api in our class.Which is irritating stuff to type everytime while creating new class.
Eclipse already have code templates which some of them are shown below:
Now we will create a code template which will show as above
Solution:
Window->Preferences->Java -> Editor -> Templates
you Will see below :
Click on "New"
Enter template Name as "slf4j"
Write description
Add Patteren given below in the box.
Click OK.
For SLF4J:
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory,org.slf4j.Logger,org.slf4j.Logger)}
private static final
Logger LOGGER = LoggerFactory.getLogger(${enclosing_type}.class);
For Log4J:
${:import(org.apache.log4j.Logger)}
private static final
Logger LOG = Logger.getLogger(${enclosing_type}.class);
Now you will see the slf4j code template in your eclipse .
Start Typing sl and CTRL+SPACE. you will...like this..:-)
No comments:
Post a Comment
Please comment here