• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

in-memory compile of java source to bytecode

 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's possible. The Javassist library can do this.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic