【问题标题】:cvc-elt.1.a: Cannot find the declaration of element 'project'cvc-elt.1.a:找不到元素“项目”的声明
【发布时间】:2022-01-13 06:24:34
【问题描述】:

错误:cvc-elt.1.a:找不到元素“项目”的声明

我不断收到此错误。每当我使用 maven 创建项目时,它都会开始显示此错误。我什至在插件标签下提到了“maven-war-plugin”,然后也更新和刷新了项目。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myfirstmvcapp</groupId>
  <artifactId>helloworldabc</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>helloworldabc Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.3.1</version>
  </plugin>
  </plugins>
    <finalName>helloworldabc</finalName>
  </build>
</project>

【问题讨论】:

  • 使用https 作为xsd 的位置而不是http
  • 请不要将您的代码显示为图像。没有人愿意重新键入从图像中手动复制的长 URL。
  • @MichaelKay 我已经编辑了问题并删除了图像,而是添加了代码。我实际上是新来的,所以我几乎不知道这是如何工作的
  • 并且提供错误信息也会很有帮助:)
  • 如果我将您的 XML 粘贴到 Oxygen 中并单击“验证”,它会很好地验证(如果我故意使其无效,则会显示错误)。所以问题与你运行验证的方式有关(你没有说什么)。你说“它开始显示这个错误”,但“它”是什么?

标签: java xml spring maven spring-mvc


【解决方案1】:

我已经找到了这个问题的解决方案,感谢@M.Deinum 在问题下方评论了解决方案。

我所做的只是将 https 添加到标签中的链接,而不是 http。

这是之前的代码:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myfirstmvcapp</groupId>
  <artifactId>helloworldabc</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>helloworldabc Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.3.1</version>
  </plugin>
  </plugins>
    <finalName>helloworldabc</finalName>
  </build>
</project>

这是最新的代码,只需要在项目标签的最后一个链接的xsd链接中添加https而不是http。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myfirstmvcapp</groupId>
  <artifactId>helloworldabc</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>helloworldabc Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.3.1</version>
  </plugin>
  </plugins>
    <finalName>helloworldabc</finalName>
  </build>
</project>

【讨论】:

  • 你会认为 mvn tidy:pom 不会破坏完美的 https 链接,但确实如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 2020-05-08
相关资源
最近更新 更多