2

I have some jars being referenced by classpath JVM arg (-cp) and other referenced by a pathing jar that includes additional jars via a Manifest file.

At runtime, how can I check the presence of a class that scans the -cp jars as well as those referenced by the pathing jar? This is required for some initialization task that scans classes for a particular annotation.

Darth Ninja
  • 1,049
  • 2
  • 11
  • 34
  • 3
    The same way you would check for any class in the classpath: `Class.forName("com.example.SomeClassOfInterest")`. – VGR Apr 06 '18 at 22:03

1 Answers1

2
try {
    Class.forName("com.some.Class");
}
catch (ClassNotFoundException e) {
    // Specified class not found
}

Note, from the Class.forName documentation:

A call to forName("X") causes the class named X to be initialized.

Justin Albano
  • 3,809
  • 2
  • 24
  • 51