Importing Code Templates

In NetBeans, Tools | Editor | 'Code Templates' tab can be used to create new code templates. This entry details how to import code templates defined in NetBeans 6.0 editor into NetBeans 6.1. Even though the details are specific to these two versions, the concept should apply to any NetBeans version.

When NetBeans is first started, the user is presented with an option to import settings from previous versions, which would also import the code templates. The following information applies to manually importing the templates from 6.0 to 6.1.

NetBeans stores the user defined code templates in the <userdir>/config/Editors/text directory. There are separate directories for each language (like x-java , x-jsp etc). Each directory has a file called CodeTemplates/org-netbeans-modules-editor-settings-CustomCodeTemplates.xml which stores the custom code templates. (You may find some custom code templates like jaxbu that you did not define; that is fine: the ide itself creates some custom code templates...)  Since the templates are stored in a plain xml file, manually copy any (or all) templates defined by you from one version's CustomCodeTemplates.xml file to another version and restart the ide. You should now be able to see the copied templates in Tools | Options dialog.

Note:

  1. The CustomCodeTemplates.xml file uses a DTD file. NetBeans 6.1's CustomCodeTemplates.xml  file has the following DOCTYPE declaration: <!DOCTYPE codetemplates PUBLIC "-//NetBeans//DTD Editor Code Templates settings 1.0//EN" "http://www.netbeans.org/dtds/EditorCodeTemplates-1_0.dtd">. If two different versions of NetBeans use different dtds, the above method may not work in cases where the definition doesn't follow the dtd.
  2. Make a backup of CustomCodeTemplates.xml before modifying it. Check the templates immediately in the ide after modification. If the ide exhibits any strange behaviour, revert back to the backup file.


Comments:

testing your comment module

Posted by poiuy on July 24, 2008 at 01:31 PM PDT #

This idea does not seem to work with netBeans6.5beta on linux..

- Wakish -
(wakish.com)

Posted by Wakish on October 16, 2008 at 09:54 PM PDT #

I tried this method on solaris and successfully imported settings from 6.0.1 to 6.5 beta. (But in general though, being essentially a hack, the method may not always work; ideally the ide would itself support settings import in a more scaled way...)

In my case:
- I had started with clean userdir for both 601 and 65beta.
- Also, I went into 65beta and created a dummy codetemplate, just so the ide itself will itself create the userdir/config/Editors/text/x-java/CodeTemplates/org-netbeans-modules-editor-settings-CustomCodeTemplates.xml . I then copied over the xml-fragment from the 6.0.1's file to the bottom of 6.5beta's file.

Do you see any stacktraces in the ide log file that might help explain where the method failed?

Also:
The jar file <nb-install-dir>/java2/modules/org-netbeans-modules-java-editor.jar in 6.5beta holds a file called org/netbeans/modules/java/editor/resources/DefaultAbbrevs.xml, which has the factory-shipped definitions. So, another hack to import code templates would be to:
- unzip the jar
- edit the xml file
- zip the jar back.
(Do remember to make a backup copy; any direct modification of jar files, if not done carefully, is very likely to break the ide).

Posted by Karthik on October 19, 2008 at 11:46 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

A blog for NetBeans users maintained by NetBeans Support team. For professional support, please check out Support Resources.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today