If I use
try {
Class.forName("my.package.Foo");
// it exists on the classpath
} catch(ClassNotFoundException e) {
// it does not exist on the classpath
}
the static initializer block of "Foo" is kicked off. Is there a way to determine whether a class "my.package.Foo" is on the classpath without kicking off its static initializer?
André
Try the forName(String name, boolean initialize, ClassLoader loader) method of Class and set the param initialize to false.
来源:https://stackoverflow.com/questions/3466568/check-if-class-exists-in-java-classpath-without-running-its-static-initializer