How to load a class using only the class name

I need to use Java Class.forName ("") to load one of my classes. The problem is that I need to load the class, specifying only the class name and NOT the full class name.

  • For example, this works, but does not meet my requirements:

    Class.forName ("reflection.Person");

  • And this is what I need, but does not work:

    Class.forName ("face");

Does anyone know how to make # 2 work? I just need to use a simple class name. Any third-party tools that will go through my folder structure to check if the class exists? This will be deployed as an executable JAR.

Thanks in advance.

+3
source share
2 answers

, , , . Class.forName(..) . , .

, . , classpath .

+4

, , "", , . Java . .

+1

All Articles