Reading a file from a jar, or anywhere on the classpath?
- by Stefan Kendall
I'm trying to build an application that builds a resource file into a jar, but I'd like to have the project runnable within eclipse. I have a basic maven 2 structure for my project, and I'm unsure how to read in the file such that it's found and used when run from the JAR or from within eclipse. Thought?
Structure:
src/main/java
src/main/resources/file.txt
Current reading method:
getClass().getResourceAsStream("/file.txt")
Is there reading method that will pick up src/main/resources/*, as well as the root level of the JAR (where resources are deployed)?