简体   繁体   English

动态类加载 - Java

[英]Dynamic Class Loading - Java

I am trying to create a program that will search a specified directory for any other jar files (which I will not know the name of). 我正在尝试创建一个程序,它将在指定的目录中搜索任何其他jar文件(我不知道其名称)。 It will then take the object from that file and create an instance of it that can be referenced later in my program. 然后它将从该文件中获取该对象,并创建一个可以在我的程序中稍后引用的实例。

I am happy to do the research on how to do this on my own, but do not know what this would be called to even start looking. 我很乐意自己研究如何做到这一点,但不知道甚至开始寻找这个会是什么。

Anyone able to point me in the correct direction? 有人能指出我正确的方向吗? Thanks 谢谢

I actually found a link that has a great example in it that is what helped me get it working the most. 我实际上找到了一个链接,其中有一个很好的例子,它帮助我让它最有效。 Find it Here 在这里找到它

You should google up java reflection and read some articles / samples upon it. 你应该谷歌java reflection并阅读一些文章/样本。

One good start would be: 一个好的开始是:

I faced problem of loading classes while working on a trading application and found following link useful. 我遇到了在处理交易应用程序时加载类的问题,并发现以下链接很有用。 http://trading.aurorasolutions.org/reflection-dynamically-loading-classes/ http://trading.aurorasolutions.org/reflection-dynamically-loading-classes/

IO: IO:

File class

Reading Jar: 阅读罐子:

JarInputStream class

Loading classes, creating instances and calling methods: 加载类,创建实例和调用方法:

ClassLoader class
Class class
Method class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM