• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a simple way to compile a source code String programmatically?  RSS feed

 
Joel Shellman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a String that has source code (1.6): full class in it.

I've look around...
javassist: can't find a way to do full class--looks like it just does parts of one. Also, doesn't support jdk 1.5/6 features
janino: doesn't support new jdk 1.5/1.6 features
jdk 1.6 ToolProvider.getSystemJavaCompiler(): Messy and looks like it is strictly file based unless maybe you could hack something together to make it work--it's already messy enough though
commons-jci: out of date

I must be missing something that can do this simply.

I could write the thing to disk and use the jdk API but... would really like to avoid such hackish things if possible...

Thanks!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel Shellman wrote:would really like to avoid such hackish things if possible...

The problem statement precludes avoiding hackish things.
 
Joel Shellman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
Joel Shellman wrote:would really like to avoid such hackish things if possible...

The problem statement precludes avoiding hackish things.


Do you consider:

new SimpleCompiler("optional", new StringReader("source code here"));

hackish?

That's apparently what janino supports. I would be happy with that... but I would really like to have support for the new language features.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I consider generating byte-code on the fly hackish, particularly if you're doing it yourself outside of a "generally-accepted" framework (lots of third-party libs do byte-code gen, obviously). Are you sure (a) your use-case warrants it, and (b) there isn't a cleaner solution? What problem are you trying to solve?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!