public static Resource getGenericResource ( String resource ) { log . trace ( "retrieving resource -> " + resource ) ; try { final File file = normFile ( resource ) ; if ( file . exists ( ) ) { return new ResourceImpl ( file . toURI ( ) . toURL ( ) ) ; } if ( resource . startsWith ( "/" ) ) { throw new IllegalArgumentException ( "Classpath resource cannot start with '/': " + resource ) ; } if ( resource . indexOf ( ' ' ) != - 1 ) { throw new IllegalArgumentException ( "Classpath resource cannot contain '\\': " + resource ) ; } URL url = getLoader ( ) . getResource ( resource ) ; if ( url == null ) { return null ; } return new ResourceImpl ( url ) ; } catch ( Exception e ) { log . error ( "Could not retrieve resource: " + e . getMessage ( ) , e ) ; return null ; } }
Gets a generic resource searching first from the file system then in the classpath if not found .