B
B
Bartholomew Izoldin2017-01-19 10:09:00
Java
Bartholomew Izoldin, 2017-01-19 10:09:00

How to correctly write paths to resources in Java?

Good day to all. I am currently learning java. I develop in intellij idea.
Undertook to implement a simple reference using javafx. The sqlite database, maven pulls up the necessary libraries to connect. Everything works while you run from idea and stops working after building in jar. In the process of studying, I realized that I was collecting it in the wrong way and with the paths I have a complete mess.
Therefore, the question is how to correctly register the paths to the resources folder?
In idea, when you create a maven project, we have the following structure

src
--main
----java
------Main
----resources
------db
--------test.db
------test.fxml
--test
pom.xml

How to correctly set the path to test.fxml and test.db in Main?
At the moment fxml (moved it to the root to Main) I get through
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));

But that's not right for me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Varfalomey Izoldin, 2017-01-19
@izoldin

Why when calling
from Main
In the terminal gives
file:/E:/JavaProjects/test/target/classes/test.db

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question