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

Community
  • 1
  • 1
jack_the_beast
  • 1,838
  • 4
  • 34
  • 67

1 Answers1

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/

Mickael
  • 4,458
  • 2
  • 28
  • 40