views:

255

answers:

3

In Eclipse 3.5, under Windows -> Preferences -> Java > Editor -> Templates, I can add code templates. However, these templates can only contain snippets which I can insert into an existing Java class.

Is it possible to create templates for whole Java classes, which I can add for example using File -> New -> My-Java-Class?

A: 

Yes! Window -> Preferences -> Java -> Code Style -> Code Templates

Select Code in the tree panel and new Java files.

nanda
Well, if I change that _all_ Java files I create in Eclipse will look different. That's not exactly what I'm searching for...
Bob
+1  A: 

What you could do is add a normal code short cut (java --> editor --> templates),

i.e. make an editor template "newcustomclass" be the contents of the class you're talking about.

Then create the new java class in the normal way, delete all the content and then use the "newcustomclass" code template to create the new auto java class.

Michael Wiles
+2  A: 

You can add 'new file wizards' to eclipse, but you'll need to write a new plugin to do it. I don't know of an easy way to do this at runtime, in the style of MS Office templates, which I think is what you're trying to do.

A new mechanism for templates might be a useful plugin, but I can't find anything that does that already.

Mike Houston