0
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.

2
  • Don't try and access classpath resources as file objects in general Commented Apr 15, 2015 at 9:38
  • I have two css files. The default one which resides in source folder and is only accessed. The latter is placed outside the source and is modified when application preferences are changed. If the latter is placed inside the source folder, as you mentioned it cannot be modified. Thank you for your reply! Commented Apr 15, 2015 at 10:55

1 Answer 1

1

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

PiChart.getScene().getStylesheets().add(this.getClass().getResource("application.css").toExternalForm());
Sign up to request clarification or add additional context in comments.

1 Comment

The above is the default method by which the start() loads the css file. Thank you for your reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.