java - Building a Jar - how to include resource files? IntelliJ 2017 -


just clarify position on question:

  • i using absolute paths because without them, tests fail.
  • i think failing understand how use relative paths.
  • as end result, want jar runs no file path dependencies.

been searching. found no solution has worked me...

i have folder format:

src/main/java/packages/javafiles.java (there several) src/main/resources/prolog_files/fileiwanttoload.pl 

in code, have state absolute path:

string currenttheory = "src/main/resources/prolog_files/kb.pl"; 

and load this:

theory theory = new theory(new fileinputstream(currenttheory)); 

such when run javafx app, , run tests, works perfectly.

however, when build jar, error:

caused by: java.io.filenotfoundexception: src\main\resources\prolog_files\kb.pl (the system cannot find path specified) 

i've done lot of searching how make work; i've tried, , failed use:

file currfile = new file(getclass().getclassloader().getresource("/src/main/resources/prolog_files/kb.pl").getfile()); 

and

inputstream stream = getclass().getresourceasstream("main/resources/prolog_files/kb.pl"); 

as trying include folder resource inside of intellij, moving folders around, trying reference .pl file without path information.

tearing hair out after 4 hours of - please help!

edit: add, i'm not using maven, ant, or this. using whatever intellij provides.

thanks!

you need tell intellij need include resource directory.

  1. create resource folder wish add external resources create resource folder

  2. make resource folder , thats it. enter image description here

ps: still suggest not use absolute path, let me know if can replacing existing 1 relative path.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -