• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving byte code of classes  RSS feed

 
Hans Oischinger
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm currently working with byte code injection libraries like cglib. These allow me to create new classes in runtime.

What I need now is to create .class files out of the generated classes. Is there a way to retrieve a class's byte code from the JVM and write it into a file?
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hans,

There was a thread about 3 months ago that detailed how to compile code programmatically. It discussed exactly what you are trying to do.

Here's an article that may help
http://www.javaworld.com/javatips/jw-javatip131.html

Cheers,
[ October 11, 2005: Message edited by: Tom Blough ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The article talks about the case where you have a .java source file, but from the question I get the impression that that is not the case here.

I'm not familiar with cglib, but using Javassist very few lines of code suffice. Have a look at the start of its tutorial.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!