Java 如何在web应用程序中使用带有路径的xsd模式

Java 如何在web应用程序中使用带有路径的xsd模式,java,jdom,xsd-validation,Java,Jdom,Xsd Validation,我正在使用JDOM解析器读取我的XML,它包括使用xsd模式进行验证 通常,为了设置xsd到解析器的路径,根据文档,语法是- SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); bui

我正在使用JDOM解析器读取我的XML,它包括使用xsd模式进行验证

通常,为了设置xsd到解析器的路径,根据文档,语法是-

        SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
        builder.setFeature("http://apache.org/xml/features/validation/schema", true);
        builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", <schema_path>);
SAXBuilder=newsaxbuilder(“org.apache.xerces.parsers.SAXParser”,true);
builder.setFeature(“http://apache.org/xml/features/validation/schema“,对);
builder.setProperty(“http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", );
它可以通过将模式路径设置为以http:开头的url或绝对路径(即c:/myFolder/schema.xsd)来工作
我的问题-如何使用web应用程序中的xsd,并且它的路径将位于web根目录下的某个位置?是否可以提供JDOM生成器的相对路径

能够回答这个问题的人也可以帮助解决我在使用xsd时遇到的另一个问题:

不能将相对路径作为字符串参数提供

要获取WEB-INF文件夹的实际路径,请重试

getServletContext().getRealPath("/WEB-INF")
要获取WEB-INF/my.xsd的实际路径,请使用

getServletContext().getRealPath("/WEB-INF/my.xsd")
getRealPath
方法将返回服务器文件系统上的绝对文件路径

如果将模式添加为jar资源,请阅读