@ Nullable public static Path findRootPathForResource ( String resourceName , ClassLoader classLoader ) { Objects . requireNonNull ( resourceName , "resourceName" ) ; Objects . requireNonNull ( classLoader , "classLoader" ) ; URL resource = classLoader . getResource ( resourceName ) ; if ( resource != null ) { String protocol = resource . getProtocol ( ) ; if ( protocol . equals ( "jar" ) ) { return getJarPathFromUrl ( resource ) ; } else if ( protocol . equals ( "file" ) ) { return getRootPathFromDirectory ( resourceName , resource ) ; } else { throw new IllegalStateException ( "Unsupported URL protocol: " + protocol ) ; } } return null ; }
Find the root path for the given resource . If the resource is found in a Jar file then the result will be an absolute path to the jar file . If the resource is found in a directory then the result will be the parent path of the given resource .