Search code examples
javaxmljarxsdear

Get file from external jar in ear project


I have a jar file with my classes where one of them have an XML validation on XSD method. All XSD files are stored at src package and saved at jar file. This validation method takes two parametrs, two Files: XML and XSD.

I want to add my jar as external jar file to ear project (WebContent/WEB-INF//lib). And call this method. XML path I get with web UI and the question is How can I get location or path of my xsd files from jar ? I need this path to load my XSD to temp file and path it as one of varaibles to my validstion method.


Solution

  • You can use this to get absolute path to file

    foo.bar.Baz.class.getResource("/data/xyz.xsd");
    

    Or this without slash to get relative path

    foo.bar.Baz.class.getResource("data/xyz.xsd");