How to write resource paths in Java? Good day to all. I'm currently learning java. I am developing in intellij idea. Undertook to implement a simple directory using javafx. DB sqlite, to connect maven pulls the necessary libraries. Everything works as long as you run from idea and stop working after building in the jar. In the process of studying, I realized that I had collected the wrong things and had no confusion with my ways. Therefore, the question is how to correctly set 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 set the path to test.fxml and test.db in Main? At the moment, fxml (moved it to the root to the Main) get through
Parent root = FXMLLoader.load(getClass().getResource("main.fxml")); But for me it is not so. Why when calling
System.out.println(getClass().getClassLoader().getResource("test.db")); from Main In the terminal issues
file:/E:/JavaProjects/test/target/classes/test.db <?xml version="1.0" encoding="UTF-8"?> http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0 UTF-8 maven maven 1.0
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <archive> <manifestFile>${project.basedir}/src/main/java/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/java/ru/varizo/maventest/resources</directory> <includes> <include>**/*.txt</include> </includes> </resource> </resources> </build>
getResource("db\test.dbl")- Senior Pomidor