mavenjsf

Eclipse Migrate to TomEE Plus 10.1 - Jakarta EE Maven Project - css resources return code 404


I have a misconfigured project and have been unable to track down the culprit.

--------------- Begin Edit -------------------

Adding for context as Basil rightly commented that the project history was referenced in the title but not expanded on in the body.

All of the changes together suggest in the solution by https://stackoverflow.com/users/20306007/life888888 resolved the 404 issue.

The project migration history is:

  1. TomEE 1.7 to TomEE 7.0
  2. TomEE 7.0 to TomEE 9.1.0
  3. TomEE 9.1.0 to TomEE 10.1.1

I don't doubt that copy & paste programming from a flawed first understanding years ago has contributed to the misconfiguration.

Prior to posting the question, I tested:

  1. Moving src->main->webapp->resources to src->main->resources after reading many Maven sources including https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html recommending the src->main->webapp->resources directory layout and thinking "I guess I've been doing it wrong all of these years. How did the project correctly generate the resources before?"
  2. Removing leading "/" from name="/default/css/tooltip.css" And numerous others.

--------------- End Edit -------------------

Does anyone see the misconfiguration?

The browser console returns code 404 for all resources after appending ".xhtml" to the resource path and not mapping the virtual path 'jakarta.faces.resource' to /resources

GET welcome.xhtml  https://localhost:8443/Test/jakarta.faces.resource/default/css/tooltip.css.xhtml net::ERR_ABORTED 404 (Not Found)

The css file is added in the main.xhtml template for page welcome.xhtml

<h:outputStylesheet name="/default/css/tooltip.css" />

The project structure is:

src -
-- main
    -- java
    -- webapp
      -- WEB-INF
        -- templates
          -- main.xhtml
         web.xml
         beans.xml
     -- resources
       -- default 
         -- css
             tooltip.css
         -- images
     

The web.xml contains:

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns="https://jakarta.ee/xml/ns/jakartaee" 
          xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" 
         id="WebApp_ID" version="6.0">
  <servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>/jakarta.faces.resource/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>jakarta.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
    <param-value>/resources</param-value>
  </context-param>

The beans.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_4_0.xsd"
   version="4.0" bean-discovery-mode="annotated">
</beans>

The pom.xml contains:

    <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>
     <groupId>Test</groupId>
     <artifactId>Test</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <packaging>war</packaging>
     <dependencies>
       <dependency>
          <groupId>jakarta.platform</groupId>
          <artifactId>jakarta.jakartaee-api</artifactId>
          <version>10.0.0</version>
          <scope>provided</scope>
     </dependency> 
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>jakarta.faces</artifactId>
        <version>4.1.3</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jakarta.servlet.jsp.jstl</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.servlet.jsp</groupId>
        <artifactId>jakarta.servlet.jsp-api</artifactId>
        <version>3.1.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.el</groupId>
        <artifactId>jakarta.el-api</artifactId>
        <version>5.0.1</version>
        <scope>provided</scope>
    </dependency>
    
    <dependency>
        <groupId>jakarta.websocket</groupId>
        <artifactId>jakarta.websocket-api</artifactId>
        <version>2.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.websocket</groupId>
        <artifactId>jakarta.websocket-client-api</artifactId>
        <version>2.1.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jakarta.security.enterprise</groupId>
        <artifactId>jakarta.security.enterprise-api</artifactId>
        <version>3.0.0</version>
        <scope>provided</scope>
    </dependency>
  <build>
    <testSourceDirectory>src/main/test</testSourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.4.0</version>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <release>22</release>
        </configuration>
      </plugin>
    </plugins>
  </build>

Thank you in advance


Solution

  • Project Tree

    st_jakarta.faces_prj
    ├── pom.xml
    └── src
        └── main
            ├── java
            │   └── com
            │       └── example
            │           └── HelloBean.java
            └── webapp
                ├── resources
                │   └── default
                │       └── css
                │           └── tooltip.css
                ├── WEB-INF
                │   ├── beans.xml
                │   ├── templates
                │   │   └── main.xhtml
                │   └── web.xml
                └── welcome.xhtml
    

    pom.xml

    For the current use of the TomEE Server, adding the following configuration is already sufficient:

    <dependency>
        <groupId>jakarta.platform</groupId>
        <artifactId>jakarta.jakartaee-web-api</artifactId>
        <version>10.0.0</version>
        <scope>provided</scope>
    </dependency>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://maven.apache.org/POM/4.0.0"
             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>
        <groupId>com.example.st.jakarta.faces</groupId>
        <artifactId>Test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
        <name>Test</name>
        <description>Jakarta EE 10 Hello Web</description>
        <properties>
            <maven.compiler.source>17</maven.compiler.source>
            <maven.compiler.target>17</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>jakarta.platform</groupId>
                    <artifactId>jakarta.jakartaee-bom</artifactId>
                    <version>10.0.0</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <dependencies>
            <dependency>
                <groupId>jakarta.platform</groupId>
                <artifactId>jakarta.jakartaee-web-api</artifactId>
                <version>10.0.0</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    
        <build>
            <finalName>Test</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.4.0</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://jakarta.ee/xml/ns/jakartaee"
             xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
             id="WebApp_ID" version="6.0">
        <servlet>
            <servlet-name>FacesServlet</servlet-name>
            <servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>FacesServlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
    
    <!--
        <servlet-mapping>
            <servlet-name>facesServlet</servlet-name>
            <url-pattern>/jakarta.faces.resource/*</url-pattern>
        </servlet-mapping>
        <context-param>
            <param-name>jakarta.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
            <param-value>/resources</param-value>
        </context-param>
    -->
    
    </web-app>
    

    beans.xml

    The same content as what you posted.

    main.xhtml

    <h:outputStylesheet name="default/css/tooltip.css"/>