Question

I'm upgrading from iBatis 2.x to myBatis 3.0.6 and I have a mapper file which includes an external entity as follows:

    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"
[
    <!ENTITY rating_analysis_state_cases SYSTEM "classpath://ibatis/includes/rating_analysis_state_cases.sql">
]>

Under iBatis this used to work fine.

The only structural change I've made is that I changed the ibatis folder to mybatis.

However when I now run it I get the following exception/stacktrace:

Caused By: java.net.MalformedURLException: unknown protocol: classpath
    at java.net.URL.<init>(URL.java:574)
    at java.net.URL.<init>(URL.java:464)
    at java.net.URL.<init>(URL.java:413)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)

Has anyone got any idea as to whether something's changed that I might not know about?

Is classpath then not a known protocol? If not, what protocol could I use and how?

Was it helpful?

Solution

It probably has nothing to do with MyBATIS. Or Xerces, for that matter, since classpath protocol should be handled outside of both components, using the separation of concern principle. I doubt iBATIS had "classpath:" protocol handler registered - in the source code I have, there is no URLStreamHandler implementation. Maybe some other component on your stack did it though, and you removed it when switching to myBatis.

Essentially, url to load resources from the classpath in Java has an answer for you.

All you need to do is to add a small class extending URLStreamHandler and implement a URLStreamHandlerFactory. Both are very simple and require around a dozen lines of code.

You can try looking in your previous technology stack, if there was a java.net.URLStreamHandler implementation done by some component (full text searching in binary files will do the trick, but then you need to see if it actually was implementing "classpath:" - the answer above provides exhaustive insight)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top