MigrationsApplication.class.getResource("DBRegister.xsd")
This part is good.
new File
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:
- Ones that work with 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.
- Crap ones you shouldn't be using.
Let's hope you have the first kind of API :)
Then we fix some bugs:
- Use 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 place- MigrationsApplication.classis located. Which is the wrong path! Your- DBRegister.xsdis in the 'root'. Include a slash at the start to resolve relative to root.
Easy enough to take care of it:
try (var in = MigrationsApplication.class.getResourceAsStream("/DBRegister.xsd")) {
   whateverYouArePassingThatFileTo(in);
}
If whateverYouArePassingThatFileTo() doesn't have a variant that takes in an InputStream, delete that library and find a better one.