17

error: cvc-elt.1.a: Cannot find the declaration of element 'project'

I am getting this error constantly. Whenever I create a project using maven it starts displaying this error. I have even mentioned the 'maven-war-plugin' under plugin tag and then updated and refreshed the project as well.

<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>
  • 9
    Use `https` for the location of the xsd not `http`. – M. Deinum Jan 13 '22 at 06:47
  • 3
    Please don't display your code as an image. No-one wants to retype a long URL copied manually from an image. – Michael Kay Jan 13 '22 at 08:48
  • 2
    @MichaelKay I have edited the question and removed the image, instead I added the code. I am Actually new here so I barely knew how this worked – Mussawir Ahmad Paul Jan 13 '22 at 09:05
  • @M.Deinum Thank You Sir, Your solution has helped get rid of this error – Mussawir Ahmad Paul Jan 13 '22 at 09:06
  • 1
    And providing the error message would be helpful too :) – barti_ddu Jan 13 '22 at 09:06
  • 2
    If I paste your XML into Oxygen and click "validate", it validates just fine (and shows errors if I make it deliberately invalid). So the problem is something to do with the way you are running the validation (which you haven't said anything about). You say "it starts displaying this error", but what is "it"? – Michael Kay Jan 13 '22 at 11:27
  • 1
    By 'it' I meant IDE. I wanted to create a simple project using with MVC functionality, I chose maven and selected archetype as 'webapp'. after the project and the files in it were successfully loaded, an error blip appeared on 'pom.xml'. Inside pom.xml, the IDE was indicating the error at the first line where the '' tag starts. when you hover on the red blip at line one(where it is indicating the error) it displays a tooltip message: error: cvc-elt.1.a: Cannot find the declaration of element 'project' – Mussawir Ahmad Paul Jan 13 '22 at 12:16

2 Answers2

25

I have Found the Solution to this problem, Thanks to @M.Deinum who commented the solution below the question.

All I did was add https to the link in the tag, instead of http.

here is the previous code:

<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>

Here is the lastest code, all that is needed is to add https instead of http to the xsd link in the last link of project tag.

<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>
7

I had to use https for all of them i.e.

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

for the warning to go away in VSCode.

pref
  • 1,651
  • 14
  • 24