Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Creating a custom class with a pre decided template(Eclipse Plugin Developement)
Creating a custom class with a pre decided template [message #1001470] Wed, 16 January 2013 19:26 Go to next message
Rajeev Mishra is currently offline Rajeev MishraFriend
Messages: 1
Registered: January 2013
Junior Member
Hi All,
I want to develop a new java file creation wizard which will create a new java file in the workspace using a predeclared template.

Please guide me.
Any code snippet or similar thread link will be most useful for me.

Thanks and regards
Re: Creating a custom class with a pre decided template [message #1001622 is a reply to message #1001470] Thu, 17 January 2013 04:22 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 450
Registered: April 2010
Location: Nantes (France)
Senior Member


Creating a brand new plug-in for that may be overkill. The Eclipse Java Development Tools already let you change the code generated while creating a new class. I've explained more about this on my blog (section 3.10) as part of a collection of articles on the JDT. You just need to configure the code templates for a new file in the properties of your project. You can then define, for example, a copyright header that should be generated on top of all your Java files. This template will be used for ll newly created classes in the project.

Now if you really want to create a wizard, you should have a look at Lars' tutorial.


Stephane Begaudeau, Obeo

Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: | Eclipse Java Development Tools Tips and Tricks

[Updated on: Thu, 17 January 2013 04:24]

Report message to a moderator

Re: Creating a custom class with a pre decided template [message #1017310 is a reply to message #1001622] Mon, 11 March 2013 14:59 Go to previous messageGo to next message
Tomas Bilka is currently offline Tomas BilkaFriend
Messages: 1
Registered: March 2013
Junior Member
It would be nice to have a possibility to configure different Java class templates for certain "types" of classes.

F.e. when I create a new class that extends another specific class, i want to populate this new class with specific code template.

I would then hit "Create new class", then pop-up opens, I enter whch class i want to extend, new class is created with populated code template.

Or even better a possibility to define a new "Create My Specific Class" key shortcut. After hitting the key, the class would be created automatically.

Re: Creating a custom class with a pre decided template [message #1017464 is a reply to message #1017310] Mon, 11 March 2013 21:54 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1409
Registered: July 2009
Senior Member
Have you looked at the Java->Editor->Templates feature? This allows you to define code snippets that will can be inserted using content assist (Ctrl-Space). Type the name of the template in your source file and hit Ctrl-Space. You will be given the template as an option. You can define variables that correspond to class name, method name, etc. This would allow you to create a class and then use content assist to fill in the details specific to the class.
Previous Topic:Initializing project state error
Next Topic:Failed to load JNI library
Goto Forum:

Current Time: Tue May 22 08:35:20 GMT 2018

Powered by FUDForum. Page generated in 0.02733 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top