1

I need to include some image files in the exported jar file, I searched a bit and found this and this answers but I can't get it to work.

so my file structure is:

root -assets --clean.png -src ... 

I added the assets folder to the build path as suggested but if I unzip the jar the files are not in the assets folder but in the root.

I tried the following codes:

InputStream i = getClass().getResourceAsStream("assets/clean.png"); InputStream i = getClass().getResourceAsStream("/assets/clean.png"); InputStream i = getClass().getResourceAsStream("clean.png"); InputStream i = getClass().getResourceAsStream("/clean.png"); 

but they none of them work, i is null. What I'm missing?

I'm using Maven

3
  • 1
    Do you use Maven ? Did you unzip your JAR to check if your resources were actually included ? Commented Jun 27, 2016 at 10:02
  • yes I use Maven, I updated the question Commented Jun 27, 2016 at 10:07
  • maven.apache.org/guides/introduction/…. Your resources must be in src/main/resources. Commented Jun 27, 2016 at 10:11

1 Answer 1

1

You should add your files into Maven resource directory src/main/resources or src/test/resources for tests.

Documentation : https://maven.apache.org/plugins/maven-resources-plugin/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.