3

I am looking for nice (java) code generation engine. I have found cglib but it is very poorly documented and I am not quite sure that it can generate actual java classes (files) and only dynamic classes. If I am wrong maybe someone knows has a link with an example.

3
  • From what source do you want to generate? UML? Commented Aug 7, 2011 at 15:10
  • 1
    cglib is what Spring uses to generate dynamic proxies. If it's good enough for them, it ought to be good enough for you. Yes, you can generate actual Java classes using cglib. That's what it's for. I'd re-read that documentation more carefully. Commented Aug 7, 2011 at 15:11
  • It should be source agnostic , it could be also UML or XML , or just some code BL , And duffymo , I did look into the source code of Cglib ,cant find the methods that print the actual class Commented Aug 7, 2011 at 15:19

3 Answers 3

4

Have a look at codemodel, used with success for my projects.

Sign up to request clarification or add additional context in comments.

1 Comment

Great ... maybe I can rewrite it to become even human usable , but definitely a start ..!!
4

Didn't really try, but you may want to take a look at another code generation Java framework called Javassist, which also has pretty thorough tutorial. Also Hibernate changed code generation framework from cglib to javassist. Quote, explaining why:

The simple fact of the matter is that development on CGLIB has largely stopped. It happens. Developers for whatever reason (the reasons are their own) move on to new priorities.

Source

2 Comments

It seems that it is only suitable for bytecode manipulation only
@Roman You're right, sorry for misunderstanding. However, after googling a bit, I found that somebody named Michael Schnell managed to add source generation to Javassist. proof
1

I just released cgV19 here: https://github.com/carstenSpraener/cgV19 it's based on a code generator i wrote in 2002 to 2006 and which is still in production use. cgV19 is a re implementation with lessons learned. It has:

  • Support for gradle
  • Uses Groovy as a template language
  • a modular "cartridge" system to add several generator for different aspects
  • small footprint

Just try it out and give me feedback would be very nice.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.