Java compiler at Runtime

房东的猫 提交于 2019-12-05 05:42:59

The eclise compiler is only 1.6 MB and should work without eclipse. You can download it here. Also it looks like it implements the JavaCompiler api.

It is licensed under the eclipse public licence so including it in your own aplication should be no problem.

I don't think it would be possible to breakup tools.jar, And also it should not be legal to include tools.jar.

Check http://forums.sun.com/thread.jspa?threadID=5161541

You could look for some 3rd party Java Compiler and change your code to use same.

But I don't know exact code for compiling using these.

Probably a better question is why?

If you need to do dynamic math calculations, then consider JEval. If you need people to write simple plugins, consider some of the dynamic languages like Javascript or Python that @Jay mentioned.

For anything else, you should require that your user download the JDK, since thats what writing Java requires. It would be hard to find a good reason why you would want to embed a compiler into your program

Jay Askren

Instead of compiling code at runtime, I would rewrite the code in a scripting language and use the scripting framework. There's no need then for the jdk and there are no legal issues to get around. Then you also have many choices of languages to use such as Beanshell, JavaScript, or jython.

do you want something like java-scripting like BeanShell? It help run java code without compile them.

You may want to have a look at the Javassist library which contains a snippet compiler suitable for creating a method to do a calculation and then using that method.

Which one is most suitable depends on your actual needs - especially how frequently you need to do this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!