3

For example, I want instead of referring to an online XSD like this:

<persistence xmlns="…" xmlns:xsi="…"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
    http://www.oracle.com/…/persistence_2_1.xsd">  <!-- online -->

To refer to a classpath XSD like this:

<persistence xmlns="…" xmlns:xsi="…"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
    org/hibernate/jpa/persistence_2_1.xsd">   <!-- classpath -->
Ori Popowski
  • 9,972
  • 14
  • 54
  • 78
  • Use an XML Catalog. See also http://stackoverflow.com/questions/8412798/how-to-load-xmlcatalog-from-classpath-resources-inside-a-jar-reliably – Harald Wellmann Feb 01 '15 at 20:45

2 Answers2

3

There's no standardized way of doing this. Some products may support classpath URIs: classpath:org/hibernate/jpa/persistence_2_1.xsd. If your product doesn't, you can probably write a plugin (LSResourceResolver) that enables the capability.

Jens
  • 63,364
  • 15
  • 92
  • 104
Michael Kay
  • 147,186
  • 10
  • 83
  • 148
2

My team had problem that Spring Boot couldn't find schema for Spring profiled unit tests when xsi:schemaLocation was provided as classpath:xmlschemas/requiredSchema.xsd

After hours of debugging the solution was to use relative path:

/xmlschemas/requiredSchema.xsd

(xmlschemas directory was in resources root)

komidawi
  • 197
  • 2
  • 6