3

I have a folder called "resources" in my Eclipse project. It's used as source folder. Everything works well compiled from Eclipse. I wanted to try it on Ubuntu so I exported it to runnable jar and tried to run but it gave me FileNotFound Exception. I checked the file structure inside the JAR and there's no "resources" folder, only files that should be inside. I'm accessing files with

File file = new File("resources/hotkeys.ini");

I also tried

InputStream in = getClass().getClassLoader().getResourceAsStream("/resources/hotkeys.ini");

but it gave me null.

How to force Eclipse to export the folder along with jar?

ssedano
  • 8,144
  • 9
  • 58
  • 96
Adrian Marszałek
  • 309
  • 1
  • 3
  • 18

2 Answers2

0

When you use "Export" functionality, you need to select all resources that need to be exported (it is visible at the top of the Eclipse export wizard window).

You can find the answer here as well: Java: export to an .jar file in eclipse

Community
  • 1
  • 1
Michal Borek
  • 4,544
  • 2
  • 28
  • 40
0

You can open the jar with 7zip or Winzip, and check the path.

Try

getClass().getResourceAsStream("/resources/hotkeys.ini");

(Or try removing the first / when with getClassLoader().)

Especially check the case-sensitivity of the paths. As opposed to Windows, inside a Jar it is case-sensitive.

Joop Eggen
  • 102,262
  • 7
  • 78
  • 129