Search code examples
javamavengetresource

how to load a resource using Class.getResource()?


I am posting this question because I have not been able to understand what I have to do in order to load a resource file from my java project.

the structure is the following one:

enter image description here

and what I want to do is to load boletinoficial.wsdl file in order to get the URL.

I have tried several ways to do that: getClass.getClassLoader.getResource(), getClass.getResource(), with absolute paths, with relative paths. But always getting null or exceptions. I also added src folder to the build path but no success.

Is there any easy way to load that file?

EDIT

ok. and now that I have the structure,

enter image description here

how do I load the resource boletinoficial.wsdl from the class App.java?


Solution

  • If you want to load a Resource, you should put them in src/main/resources, as they'd be ignored in src/main/java