Storing code snippets in eclipse

You might want to store those two snippets into a code template, as explained in this tutorial.

And do not forget about the possibility to quickly execute any kind of java code snippets in a scrapbook (not exactly what you want, but it can come in handy at times)

Newtopian adds (in the comments)

In fact templates become much more powerful by adding variables and tabstops within, so your example above would become dbHandle ctrl+space. It would copy snippets from both parts and place your cursor right in the middle.


Eclipse also offers something very similar to the templates feature described by VonC called (would you believe) snippets. Window > Show view > Snippets.

To add a new snippet category: Right click in the Snippets window and click Customize... Click New > New Category. Enter a category name if necessary (e.g. "Java"). Click Apply. With your chosen category selected, click New > New Item. Enter your snippet.

To use a snippet, put the cursor where you want to insert the snippet, then double click on a snippet in the Snippets window.


I ran into the Snip2Code plugin recently. It did the job, and I can collect and search snippets in a quick way.


Well a picture worths a thousand words, what about this one?

enter image description here