离线时使用外部 xsd 文件解析 tomcat web.xml

Parsing tomcat web.xml with external xsd file when offline

当我尝试在没有互联网连接的情况下启动 tomcat 时,解析位于 CATALINA_HOME/conf/web.xml 的 web.xml 时会抛出错误。 (CATALINA_HOME is/usr/share/tomcat8.5 在我的环境中)

org.apache.tomcat.util.digester.Digester.error Parse Error at line 20 column 193: Schema error: no attribute named "lang" was defined in schema : http://www.w3.org/XML/1998/namespace.
 org.xml.sax.SAXParseException; systemId: file:/usr/share/tomcat8.5/conf/web.xml; lineNumber: 20; columnNumber: 193; Schema error: no attribute named "lang" was defined in schema : http://www.w3.org/XML/1998/namespace.

我确定问题是它正在尝试获取位于 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd 的 xsd 文件,但由于它处于离线状态,因此无法获取,而且 web.xml 命名空间不完整。

我试过下载 web-app_3_1.xsd 并将其放在 /usr/share/tomcat8.5/conf/web-app_3_1.xsd 中,然后在 web.xml 中引用它通过将前几行更改为

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee web-app_3_1.xsd" 
version="3.1">

但它仍然会抛出相同的错误。我也试过指向文件 像 file:///usr/share/tomcat8.5/conf/web-app_3_1.xsd 但这也不起作用,因为它抛出 FileNotFoundException 即使文件存在并且属于 tomcat 用户。

感谢任何解决问题的帮助或允许在没有互联网连接时进行部署的解决方法!

我们通过将 STRICT_SERVLET_COMPLIANCEtrue 更改为 falsetomcat/conf/catalina.properties 中找到了解决方案。这会阻止它根据其架构文件检查 xml,并且由于它不再尝试获取架构文件,因此它允许它脱机工作。