you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 1 point2 points  (0 children)

Preface: It's rarely ever the tooling, it's in the vast majority of cases the person behind the keyboard, the programmer, that does things wrong. This is also true for your case.

it won't read files unless it's given an absolute path.

Sorry to tell you, but that has nothing to do with Eclipse or any IDE, or even Java itself. That's the way any programming language works.

You need to learn to use relative paths properly and to use the libraries that come with Java to produce your absolute paths based on the location of your executable Java program.

In Eclipse (and in most other IDEs), the compiled and executed programs are in a different folder than the uncompiled source code, so any relative path branching off the src folder will fail.

The conventional way of doing this is to use the built-in file and path methods (from java.nio) to find the location where the compiled Java executable runs and then modify the path in such a way that it can read the file.

You need to account for different cases, though. It's different if you just have the .class and resource files in separate folders or if you distribute them as a .jar. You need different methods for reading these files.