Question

In my project i write into and read from a project.txt file. This project.txt file is first reading in by programm start. All works perfectly, but if i export my project as a .jar file and try to execute this .jar file, then my programm says, that he could not find the project.txt (i created this error-message).

The path of project.txt is "./res/project.txt". The res-folder is included in the build-path of this project. I'm using Eclipse.

What i'm doing wrong?

Was it helpful?

Solution

TO READ

Two possible causes:

  1. you are trying to access the project.txt through java.io and not as resource (please post the code)
  2. you access through ClassLoader.class.getResourceAsStream("/res/project.txt"); but the file was not exported into the jar (please post the code)

in othe words: the "./res/project.txt" is near the eclipse project path but outside the scope of the jar.

TO WRITE

Finally the writing into the jar file is absolutly not Java compliant, it should work in some cases such as ear or war and not jar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top