I need to access to a xsd file that it's inside my jar. My problem is that my classpath is C:\Users\fabio\Documents.
My jar file it's in that path too , so how can I get the file that I need?
I tried File xsdFile=new File(String.valueOf(MigrationsApplication.class.getResource("DBRegister.xsd"))); but got this error message schema_reference.4: Failed to read schema document 'file:/C:/Users/fabio/Documents/null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

This part is good.
Nope. File refers to an actual file on your harddisk. And that resource aint one of those. You can't use File here. Period.
There are only two APIs that read resources:
InputStreamor some other abstracted source concept such asURL. Perhaps in addition (with e.g. overloaded methods) to ones that take in aFile,Pathor (bad design)Stringrepresenting a file path.Let's hope you have the first kind of API :)
Then we fix some bugs:
getResourceAsStreamto get an InputStream,getResourceto get a URL. Which one should you use? Well, check the API of where you're passing this resource to. For example, swing'sImageIconaccepts URLs, so you'd usegetResourcethere..getResource("DBRegister.xsd")looks for that file in the same placeMigrationsApplication.classis located. Which is the wrong path! YourDBRegister.xsdis in the 'root'. Include a slash at the start to resolve relative to root.Easy enough to take care of it:
If
whateverYouArePassingThatFileTo()doesn't have a variant that takes in anInputStream, delete that library and find a better one.