Options for dynamic compilation in Java 5

本小妞迷上赌 提交于 2019-11-29 04:49:29

What you want is something like Janino. We've used it for years. You give it (near standard) code and it gives you the classes so you can use them. It actually has quite a few different modes and supports the 1.5 syntactic sugar and auto-boxing and such.

If you call javac, not only will you have to be ready for anything it does, you'll then have to handle putting the class in the right place or making an additional classloader.

Janino is very easy. It should be exactly what you are looking for.

Invoking javac programatically:

http://www.juixe.com/techknow/index.php/2006/12/12/invoke-javac-at-runtime/

   com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main();  

   String[] options = new String[] 
   {  
      "-classpath", classpath, "-d", outputDir, filename  
   };

   javac.compile(options);

All app servers do this for JSP for ever, so obviously it is possible. Checkout tomcat source code maybe?

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