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
InputStream or some other abstracted source concept such as URL. Perhaps in addition (with e.g. overloaded methods) to ones that take in a File, Path or (bad design) String representing 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
getResourceAsStream to get an InputStream, getResource to get a URL. Which one should you use? Well, check the API of where you're passing this resource to. For example, swing's ImageIcon accepts URLs, so you'd use getResource there.
.getResource("DBRegister.xsd") looks for that file in the same place MigrationsApplication.class is located. Which is the wrong path! Your DBRegister.xsd is 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.