Simon Bauer
Simon Bauer

Reputation: 37

Ressources can't be found in maven build

I wanted to migrate my local prototype to a maven build and start getting productive. But unfortunately when calling

loader.setLocation(getClass().getResource("views/TaskWindow.fxml"));

On runtime it seems that maven doenst find the ressource xmls. I tryed "TaksWindow.xml", "../views/TaksWindow.xml" "views/TaskWindow.xml" and "/views/TaksWindow.xml" but somehow it always gives me "no location set" error.

My project structure looks like this:

enter image description here

Any ideas why?

Upvotes: 0

Views: 29

Answers (1)

SilverNak
SilverNak

Reputation: 3381

The path you specified is a relative path. Which means the classloader will look for a views folder at the location of the class (i. e. its package). You propably want to use an absolute path.

Try the following code, notice the leading /.

getClass().getResource("/views/TaskWindow.fxml")

For more information, see this answer.

Upvotes: 1

Related Questions