2

I am trying to deploy the program by making it into an executable jar file. When I run the program directly from IDE (IntelliJ), everything is fine. But after I make jar file out of my project, when I run that jar file, I get errors like:

java.io.FileNotFoundException: src\JsonFiles\Words.json (The system cannot find the path specified)
aeruhxi
  • 556
  • 2
  • 5
  • 19
  • Are you sure your JSON files are bundled within the jar? – David Siro Feb 03 '16 at 18:49
  • @David Siri Nope. How do I make sure? Can you help me in this one? I configured artifact with "build on make" and run a build on the project as I followed this: http://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly – aeruhxi Feb 03 '16 at 19:10
  • json files are inside the project folder. So, should they not be bundled automatically when I build artifact? – aeruhxi Feb 03 '16 at 19:17
  • 1
    That depends how you build your jar. For example, with Maven, only files in `src/main/java` and `src/main/resources` are included in the resulting jar by default. – David Siro Feb 04 '16 at 07:44

1 Answers1

2

Don't use relative paths to src folder, open an input stream to the file where it's located relative to a class:

InputStream in = SomeClass.class.getResourceAsStream("Words.json");

where Words.json and SomeClass.java exists in the same folder/package.

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417