I need to be able to check whether certain system packages exist when my Java app loads. For my specific use-case the system packages are listed in a .properties file. I assumed that I could use for example ClassLoader.getSystemResource("javax/swing"); to test whether a specific package exists, but this doesn't work. However the following works for other packages on my classpath: myClassLoader.getResource("com/example/mypackage");
This is a simple runnable example:
The console output you will see when you run this program is:
Found [com/example/mypackage] with myClassLoader
Could not find [javax/swing]
Is there any way to check for system packages without having to know the classes they contain?
For the curious, my application is embedding the Felix OSGi runtime into a webapp. The system classes which my OSGi bundles need are specified in a .properties file and I would like to be able to check that all the packages exist before I boot OSGi. Without the check, the only way I know if a system package doesn't exist (for example, I miss spelt it in the .properties file) is when an OSGi bundle that needs it tries to load a class and gets a NoClassDefFoundError.