引用文件包含错误(http://java.sun.com/xml/ns/javaee/web-app.xsd)

时间:2015-11-19 06:11:47

标签: java xml eclipse xsd

我在Eclipse中遇到了这个错误:

  

引用文件包含错误(http://java.sun.com/xml/ns/javaee/web-app.xsd)。有关更多信息,请右键单击    问题视图中的消息,然后选择"显示详细信息..."

任何人都可以帮助我吗?有什么问题?提前致谢。我的代码是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets             and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/dispatcherServlet/servlet-context.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

4 个答案:

答案 0 :(得分:2)

尝试将此URL用于架构定义:

http://oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd

如上所述@Renardo,以下网址......

http://java.sun.com/xml/ns/javaee;http://java.sun.com/xml/ns/javaee/web-app.xsd 

...重定向到导致Eclipse内部错误的HTML页面。

答案 1 :(得分:0)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

看起来问题出在MyEclipse附带的Java EE JAR上......我永远不会鼓励你将插件从一个版本复制到另一个版本(仅供将来参考,它可能导致一些问题)。 所以尝试上面一个

答案 2 :(得分:0)

虽然我的schemaLocation指向web-app_3_0.xml,但我遇到了同样的问题。 2_4问题没有出现。现在我发现,用作http地址

java.sun.com/xml/ns/j2ee/web-app_2_4.xsd

被重定向到

www.oracle.com/webfolder/technetwork/jsc/xml/ns/j2ee/web-app_2_4.xsd

这是一个有效的XSD文件。但是,与&#34; 3_0&#34;相同的网址而不是&#34; 2_4&#34;被重定向到 ... / technetwork / java / index.html ,这是一个HTML文件,包含Eclipse抱怨的文本。

我不知道是否

  • Oracle应在该URL下提供XSD,或
  • Eclipse应该尝试从其他地方获取XSD,或者
  • 我应该更改我的名称空间声明。

当我从&#34; ... / xml / ns / j2ee &#34;更改命名空间时,我的Eclipse错误消失了。到&#34; ... / xml / ns / javaee &#34;并使用Oracle网站上指向正确XSD的URL。抱歉,我无法发布网址,我的低声望不允许。

答案 3 :(得分:0)

每次遇到此错误,我都会这样做

项目->属性->项目构面 在右侧面板中找到“动态Web模块”并获取此版本。

例如,在我的项目中,我正在使用动态Web模块 3.1

为此,我需要使用http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd">
</weblogic-web-app>