I am working on a JavaFX 8 (maven) project. I want to store an fxml file inside of sources (not inside resources) folder.
When I store my fxml to location /src/main/resources/views/b/MyFxml.fxml I am loading it without errors using the command,
new FXMLLoader(getClass().getResource("/views/b/MyFxml.fxml"));
Is there any way to load my fxml file from /src/main/java/package/name/RoleView.fxml location?
Java does not make distinction between resources and sources. As long as your fxml file is visible in classpath (packaged into *.jar appropriately) you can reach it the same way. Given that you use maven, this is the configuration you need:
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
</includes>
</resource>
...
</resources>
...
</build>
...
</project>
Then, this line should work to load your file:
new FXMLLoader(getClass().getResource("/package/name/RoleView.fxml"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With