I have compiled .jar file using IntelijIDEA from few classes. The project structure is like this:
src -> .class;
res -> buttons -> Draw.png
When I run this project from IDEA it works fine. But when I run compiled .jar file it does not.
I think the problem is with finding my Draw.png
file. One of the class uses the following line of code:
String startButtonHover1 = Draw.png;
BufferedImage startButton = ImageIO.read(this.getClass().getResource("buttons\\" + startButtonHover1));
If I run .jar file via cmd it reports the error in the ImageIO.read : input == null!
How it can be solved? Maybe some cofigurations of IntelijIDEA have to be changed before building jar file and I did not do it.
I also tested these lines:
System.out.println(Main.class.getResource("buttons\\" + startButtonHover1));
System.out.println(Main.class.getResource("\\buttons\\" + startButtonHover1));
System.out.println(Main.class.getResource("res\\buttons\\" + startButtonHover1));
System.out.println(Main.class.getResource("..\\res\\buttons\\" + startButtonHover1));
System.out.println(Main.class.getResource(".\\res\\buttons\\" + startButtonHover1));
All of them generate null as well while first two give in appropriate output when I run the code from InteijIDEA.
Any suggestions will be appreciated.