Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to a classpath XSD in xsi:schemaLocation?

Tags:

xml

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 -->
like image 247
Ori Popowski Avatar asked Oct 15 '25 18:10

Ori Popowski


2 Answers

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.

like image 132
Michael Kay Avatar answered Oct 18 '25 12:10

Michael Kay


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)

like image 24
komidawi Avatar answered Oct 18 '25 11:10

komidawi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!