开发者

Load Java class file on the fly

In one of my ongoing applicati开发者_StackOverflowon I want to load java class file to the application when it runs. This particular java file is generated by the user and I don't know the name of that file. but I know the structure of that file (methods, variables , etc.) and location of that file. I know how to load java file using ClassLoader but for this instance it doesn't useful since I don't know the file name. so how do I load java file to my application and access it's method (These user generated java files are stored in one folder so it is ok to load all the java files at once) Thanks!


Use an URLClassLoader.


If you know the directory the file is in, you can search it to find the class and use the ClassLoader to load it.


It appears you need to create your own ClassLoader.

Try reading this:

  • http://onjava.com/pub/a/onjava/2005/01/26/classloading.html
  • http://www.ibm.com/developerworks/java/library/j-dyn0429/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜