views:

949

answers:

6

For C#, I have often used CodeSmith and lately the T4 generator which is part of Visual Studio.

I'm looking for something similar for Java, in particular an Eclipse add-in since I do all my Java development using the Eclipse IDE.

A: 

I'm not a C# man so I don't know what the equivalents would be, however I've found xdoclet to be very good in the past. I don't think it integrates with eclipse as such but you can run it from an ant script. Does things like generating Hibernate mapping files from annotated Java classes. Useful if that's what you're looking for :)

Phill Sacre
+5  A: 

I've found that freemarker does a pretty good job for generating any type of code. From the website:

FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.

It is used by struts2 a lot. The website has a long list of other products that use freemarker.

Vincent Ramdhanie
+2  A: 

I have worked with both Velocity and StringTemplate. Velocity is a bit more conventional (think JSP/ASP concepts), while StringTemplate seems a bit cleaner. in a sense described in this Artima interview. Both are pure templating engines, and will require you to write some code around them, if you want to do full-blown code generation from a model.

StringTemplate is used internally by ANTLR, which may be useful to your effort.

As an alternative approach, you could go with Eclipse, using EMF and JET.

joel.neely
+3  A: 

If you are a bit more ambitious you could also use http://www.openarchitectureware.org/

Mauli
+1  A: 

eclipse has a built-in template system.

look in window -> preferences -> java -> code style -> code templates

NSherwin
+1  A: 

You might look at my plugin : http://fast-code.sourceforge.net/. It allows one to select multiple fields and generate code using user specified velocity templates.

fastcodejava