Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have several templates for Java files in Eclipse?

I'd like to have several different templates for new java files in Eclipse. Is this possible?

Basically when I am creating a new Java class file in Package Explorer I'd like to use a template X as a base for new file, when I am creating a new unit test class I'd like to use template Y, when I am creating a Wicket component class I'd like to use template Z, etc.

Also is it possible to configure Eclipse so that when I create a new Java class, Eclipse will generate corresponding new unit test class automatically?

like image 210
Juha Syrjälä Avatar asked Sep 01 '26 20:09

Juha Syrjälä


1 Answers

I am not sure if this is what you want, but you can add new wizards to Eclipse using the org.eclipse.ui.newWizards extension point.

Here is the corresponding documentation in Eclipse help.

Another (less elegant) way of doing this is to add your own templates (e.g. DAO) under the Java editor (Window->Preferences->Java->Editor->Templates) so when you type DAO and Ctrl + Enter it, it expands to the full template you want. This way creating a new empty file, typing DAO and autocompleting would transform into a full file snippet.

Hope it helps!

like image 149
jhurtado Avatar answered Sep 04 '26 11:09

jhurtado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!