简体   繁体   English

Java反射加载类

[英]Java Reflection to load classes

I am given an external folder called "ATM". 我得到了一个名为“ ATM”的外部文件夹。

In the folder, it only contains files that ends with .class. 在该文件夹中,它仅包含以.class结尾的文件。

How would I load it? 我将如何加载?

I've been using Class.forName. 我一直在使用Class.forName。 It does not work. 这是行不通的。

I need to load it to use Java's reflection on it. 我需要加载它以使用Java的反射。

You have basically two options: 您基本上有两个选择:

  1. make sure the folder is in the class path when you start the program 启动程序时,请确保文件夹位于类路径中
  2. create an java.net.URLClassLoader to load the classes 创建一个java.net.URLClassLoader来加载类

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

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