My problem is that the path just works when it's in the project but when i try to run it in the .jar that i created doesnt seem to work
@Override
public void initialize(URL location, ResourceBundle resources) {
ReadPath("clock/src/main/resources/Csv/Path.txt");
ReadCsv("clock/src/main/resources/Csv/MondayA.csv");
ReadCsvL("clock/src/main/resources/Csv/MondayL.csv");
SetTime();
}
This is incorrect. You are using relative paths which are relative to your project path. And when you create the jar
file, it will not be able to find them since the files that you are searching for are in the jar file itself.
The correct way to do this is:
@Override
public void initialize(URL location, ResourceBundle resources) {
ReadPath(this.getClass().getResource("/Csv/Path.txt").toString());
ReadCsv(this.getClass().getResource("/Csv/MondayA.csv").toString());
ReadCsvL(this.getClass().getResource("/Csv/MondayL.csv").toString());
SetTime();
}
Now the paths are the jar paths & the files are read from the resources
folder which is located inside the jar.
------------ EDIT -------------
Most likely your resources
folder, is not marked as the directory folder. From your Screenshot, I can see that you are using VS code (bad idea when coding with java). There are a lot of IDEs that make your life simpler and save you headaches as the one that you have.
I also see a pom
file, which means you are using maven.
Following this these instructions, this is how you mark the directory through maven:
<project>
...
<build>
...
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
...
</build>
...
</project>
Or try moving your resources folder IN src/main
.