开发者

Java - let user write own code, then compile it, then use it within same runtime

I need to perform following steps:

  1. Let user write own code - no problem, it's just one interface to implement and I save a file
  2. Compile it - no problem, I used ToolProvider.getSystemJavaCompiler() and created .class file
  3. Let user use this new code - h开发者_Python百科ere I am stuck. I have .class file and now what? I need somehow add it in my project and I don't know how.

Thanks for help!


Use a URLClassLoader to load the classes. Then you can use reflection to instantiate and manipulate them.


What you need to do is write your own ClassLoader that will load the classes you have just compiled.
There are many examples on the web on how to do that.

Here is one to load from the web: http://kazi-masudul-alam.blogspot.com/2008/01/java-classloader.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜