I would like to test if a particular package is known to the current classloader or system. Package.getPackage(String name) seems to return null thus im stuck. ClassLoader does not contain any method that does the same thus im stuck…
I d rather not load a class in the package to test if it is present, surely theres a better way.
Any pointers would be appreciated.
Package.getPackage(String name)is the right tool for the job. Make sure you’vePackage.getPackages()to see what’s availablegetClass().getPackage()and thenPackage.getPackage(String name)The method searches for the package in the current classloader only (or System classloader if current classloader is null). If no class in the package is loaded in the current classloader the package will no be present.