问题
When I am trying to start Liquibase (Karaf is used), I get the following error
'Failed to read schema document http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xml, bacause 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not '
If computer is connected to internet, this error is not reproduced.
回答1:
I stumbled across this myself recently.
You need to change this:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
and remove the URL to the XSD:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog-3.0.xsd">
Note the space between http://www.liquibase.org/xml/ns/dbchangelog
and dbchangelog-3.0.xsd
. The first element is the URI for the namespace, the second element points to the actual XSD file. If that doesn't include a URL, the XML parser will try to use a local file.
Then put the actual XSD into the same directory where the changelog XML is located.
You need to download that from a computer with internet access of course, e.g. using:
wget http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
or by simply opening the URL with the browser and then saving the file.
Note that you also need to specify a .xsd
file for the schema location, not a .xml
(as it is shown in the question).
回答2:
This problem was fixed. It turns Liquibase-osgi.jar contains own packages and also it contains liquibase.jar. When LiquibaseEntityResolver.java tries to find *.xsd, it finds two files *.xsd with same name. And after that liquibase throws Exception. I deleted duplicate files and everything was working
BTW Root element of changelog file looks like
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
回答3:
Thk for your awswer.
But, liquibase has own xsd file in liquibase/parser/core/xml/.
If we run liquibase, for example, in tomcat, it works correctly http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd" will be replaced to liquibase/parser/core/xml/dbchangelog-3.0.xsd by LiquibaseEntityResolver.java
回答4:
For those using Maven and the liquibase-maven-plugin plugin, be sure to add all liquibase dependencies into the plugin dependencies themselves.
e.g.
<plugin>
...
<artifactId>liquibase-maven-plugin</artifactId>
...
<dependencies>
<dependency>
...
<artifactId>liquibase-core</artifactId>
</dependency>
</dependencies>
</plugin>
I had a similar issue where liquibase commands would not work while disconnected, because the plugin could not resolve the local schema .xsd file.
来源:https://stackoverflow.com/questions/32350054/liquibase-fails-if-computer-is-not-connected-to-internet