Good day,

I'm trying to compile a jar archive, but when I launch it, an exception is thrown when accessing the file.

FXMLLoader loader = new FXMLLoader(Main.class.getResource("/view/mainView.fxml")); 

Obviously, when building an artifact, you need to specify this file, tell me how.

Project structure:

project structure

  • What are you doing about the project? - etki
  • I simply add an artifact to idea and indicate the Main class - Arashigor
  • handles add? or write ant-script? - dgzargo
  • ant script if you can - Arashigor
  • Can't you just add it to resources? fxml and css is not a place in src. Then go to "classpath: /view/MainView.fxml" - Victor Khovanskiy

2 answers 2

The problem is in the register, the file you have is called with a capital letter, and which you are trying to call with a small one, that's why he does not find the file

 FXMLLoader loader = new FXMLLoader(Main.class.getResource("/view/MainView.fxml")); 
  • Oddly enough, this is not the problem. When run from ide, everything works. - Arashigor
  • @Arashigor The fact is that the idea ignores the register and reads, but when you start the jar, it reads through jre, but it does not ignore it anymore - RodGers
  • I fixed it, but when I run the jar file, it’s still java.lang.IllegalStateException: Location is not set. - Arashigor
  • @Arashigor Try this FXMLLoader loader = new FXMLLoader (Main.class.getResource ("/ src / view / MainView.fxml")); - RodGers

Solved the problem with the help of maven'a adding to pom.xml

  <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.fxml</include> <include>**/*.css</include> </includes> </resource> </resources> 

and maven-assembly-plugin

  <plugin> <artifactId>maven-assembly-plugin</artifactId> ... <descriptorRef>jar-with-dependencies</descriptorRef> <manifest> <mainClass>application.Main</mainClass> </manifest> ... </plugin>