문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top