Skip to content

Instantly share code, notes, and snippets.

@pete911
Last active January 3, 2016 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pete911/8538388 to your computer and use it in GitHub Desktop.
Save pete911/8538388 to your computer and use it in GitHub Desktop.
Java - get resources from classpath
import org.springframework.core.io.Resource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
...
PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resourceResolver.getResources("conf/**/*.properties");
Resource resource = resources[0];
/* get path */
String path = ((ClassPathResource) resource).getPath();
...
---------------------------------------------------------------------------------------------------
import org.springframework.util.ResourceUtils;
import java.io.File;
...
File globalConfig = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "some.properties");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment