I've got this error in project faces-config.xml file in my IntelliJ IDE:
Element faces-config must be declared
Here is my faces-config.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
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
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
version="2.3">
</faces-config>
And pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
How can I fix this?
CodePudding user response:
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd"
Try opening http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_3_0.xsd in your favorite webbrowser. It returns 404. In other words, this URL is not correct. The IDE's built-in XML parser is also struggling this way. It cannot find the declaration of <faces-config>
root element there.
It's not clear which JSF version exactly you intend to develop with. If it's 2.3, as indicated by version="2.3"
, then you should be using http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd instead, as specified in "Java EE 8 Schema Resources" section of the webpage behind http://xmlns.jcp.org/xml/ns/javaee.
<faces-config
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
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
version="2.3">
But if it's indeed 3.0, the first Jakartified version (i.e. you should be using jakarta.*
package for Jakarta EE API over all place instead of javax.*
package), then you should be using the following deployment descriptor root declaration as specified in "Jakarta EE 9" section of the webpage behind https://jakarta.ee/xml/ns/jakartaee.
<faces-config
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
version="3.0">