TaTCodeTemplateBackup

Code Template Backup

One thing I excessively use in NetBeans is the ability to introduce custom templates to insert a more or less long block of code using a convenient abbreviation to be expanded to actual code using a keybinding like
TAB
. This might be configured using "Tools" -> "Options" -> "Editor" -> "Code Templates":

File:TaTCodeTemplateBackup/cdb-01-templates TaTCodeTemplateBackup.jpg

Given code fragments which are frequently used (in example, I do have a bunch of templates dealing with inserting
logger.whatever(...)
lines into my code), this is an immensely comfortable feature. And then, after spending some hours of working and customizing your templates in NetBeans 6.0, you want to have a first look at 6.1M1, start up the new IDE, merrily enter one of your templates - and nothing happens.

At second thought, this comes as no surprise as each of the NetBeans installments per default uses a different file system folder to store its settings, which is sane if you don't want to wreck your everyday working environment just by installing and launching a milestone build, but of course, at the very least in this special case, the loss of previously made settings can be annoying.

There's an easy way getting out of that however: As pointed out, NetBeans does store its configuration in a special place on your hard drive, which is likely to be found in one of the following places (subsequently referred to as
<config>
)
  • Windows:
    C:\Documents And Settings\<your-login-name>\.netbeans\<version>\config
  • Unix/Linux:
    $HOME/.netbeans/<version>/config
... where
<version>
usually denotes the NetBeans version loading its configuration from that very folder. (Dealing with Unix installations of NetBeans, you'll quickly see that there's a rather easy way telling NetBeans where to load from / store to its configuration, but that's beyond this short tip.) This folder contains all the settings made in your IDE, including your code templates. To find them, have a look at the
<config>/Editors/text
folder, which has a structure more or less like this:
<config>/Editors/text
	|
	/base
	|
	/bat
	|
	...
	|
	/x-java
	   |
	   /CodeTemplates
	   |
	   ...
This folder, as you'll figure out browsing the structure for a while, contains editor settings for different (textual) file types known to your IDE. And, this is also where to find your code template configurations: In
<config>/Editors/text/<your-file-type>/CodeTemplates
, if you added any custom templates for {<your-file-type>}, you will find a file named org-netbeans-modules-editor-settings-CustomCodeTemplates.xml. Having a closer look at it, you'll figure out that this definition contains the things you used to set up in your IDE:
    ...
    <codetemplate abbreviation="ldec" xml:space="preserve">
        <code>private static final Logger logger = Logger.getLogger(${cursor});</code>
    </codetemplate>
    <codetemplate abbreviation="linfo" xml:space="preserve">
        <code>logger.info("${cursor}");</code>
    </codetemplate>
   ...
So, straightforward, copying this file to the same place in a new NetBeans versions
<config>
folder before starting your IDE will make all your templates come to life again, which certainly is a good thing...
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo