• Post Reply Bookmark Topic Watch Topic
  • New Topic

in-memory compile of java source to bytecode  RSS feed

 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Is it possible, using existing utilities, to generate bytecode from java source at run-time without actually writing any .java or .class files to the filesystem?

Thank you,
Yuriy
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's possible. The Javassist library can do this.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just guessing, but cglib might be able to do that: http://cglib.sourceforge.net/
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies!

Jeff, can cglib generate classes from java source? I couldn't find a way to do that.

Ulf, I noticed that the JavaAssist library allows the creation of methods from source codes, but can it create an entire class given the contents of a .java file? We're thinking of using a java source generator like Axis' WSDL2Java to generate java source code, but in memory instead of on the file system. Then we would compile the source into a bytecode, again in memory. That way we could created classes at runtime without touching the filesystem. We would prefer to compile the class sources whole, without parsing for bits and pieces to add to a new class definition.

Thank you,
Yuriy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!