kingspp
kingspp

Reputation: 311

Java: File path error

File defaultCss=new File(this.getClass().getResource("application.css").getFile());

PiChart.getScene().getStylesheets().add("file:///" + defaultCss.getAbsolutePath().replace("\\", "/"));

The above line in Controller.java fetches the required resource in Eclipse while running, but when exported to an executable JAR, it is not fetching the file.

Because: In Eclipse the line fetches src/com/piscope/application.css

In JAR, the path is: com/piscope/application.css

Please let me know the path to be set so that one can run both eclipse and JAR executions without errors.
Note: Since the file is the source for the software package,the file needs to be inside the JAR file.

Upvotes: 0

Views: 91

Answers (1)

eckig
eckig

Reputation: 11134

Just use the following (no need to format the syntax by yourself):

PiChart.getScene().getStylesheets().add(this.getClass().getResource("application.css").toExternalForm());

Upvotes: 1

Related Questions