Reading a file from a jar, or anywhere on the classpath?
Posted
by Stefan Kendall
on Stack Overflow
See other posts from Stack Overflow
or by Stefan Kendall
Published on 2010-03-18T03:17:12Z
Indexed on
2010/03/18
3:21 UTC
Read the original article
Hit count: 404
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)?
© Stack Overflow or respective owner