views:

310

answers:

1

I am about to start developing a small Java desktop app. The app is just an engine for which the user provides Java classes to do the work (translating input to output).

I would like the user to provide actual Java classes as files that can be loaded (and reloaded) on the fly.

For this particular use, is there any reason why Java would be more cumbersome than Groovy or Beanshell? I'm not asking for a comparison of Groovy/Beanshell and Java as there are many. Rather, I want to know if it's easier to dynamically load Groovy or Beanshell classes from files compared to Java.

For Java 1.6, is the JavaCompiler the best way to dynamically load code? I would like to use all language features so I think Janino is out. Also, any problems with reloading?

Note: I have seen this and this, but I'm not sure they answer my question.

+1  A: 

JavaCompiler is very versatile, but it entails a minor, potential configuration problem: In javax.tools, ToolProvider.getSystemJavaCompiler() identifies the compiler's class as com.sun.tools.javac.api.JavacTool. On some platforms, that class is not part of the JRE; a JDK appears to be required. Here is an example.

Also consider javax.script, discussed here. Several scripting engines are supported.

trashgod
Thanks for that. Any reason to prefer something like Rhino over one of the "hot" current languages (Groovy, mostly)?
Yar
I'd guess it would depend on the users' preference. If you target a javax.script compliant implementation, you may be able to allow your users to choose from a list of supported languages.
trashgod
Good point. Thanks, still considering, I'll check into the scripting engines too.
Yar