Reputation: 647
I have this project structure:
If the pic.jpg was under package, then getClass().getResource("pic.jpg")
works absolutely fine. getClass().getResource("/web/image/print/pic.jpg")
doesnt work as well. But I want to place all my images under image folder and refer it in the java file.
Upvotes: 0
Views: 126
Reputation:
Seems your files are not copied to bin/ directory. Change your build script to copy them to output directory
getClass().getResource()
will use class loader to load class, since those files need to be in classpath
Upvotes: 0
Reputation: 593
You should get the application runtime path and rebase the path to the folder which images locate.
You can use the code:
String path = new File(".").getCanonicalPath();// or System.getProperty("user.dir")
Upvotes: 1