MarekChr
MarekChr

Reputation: 1160

WildFly returns 404 error while same Maven project works fine on TomEE

I am trying to make Hello World web application using Eclipse and Java-ee 8, but i can not access .xhtml file, getting 404 error.

It is Maven project.

Before i deploy and run on server, which is WildFly 21.0.2, i do Maven -> Update and Run as -> Maven -> Clean verify.

The server is starting OK, because i can access it at localhost.

Page i am trying to access is index.xhtml, which is in webapp folder next to WEB-INF folder.

There is a similiar question: Error 404 - Not Found Wildfly, but restarting Eclipse did not help.

Page is accessible when i deploy to Apache TomEE 8.0.5 web profile.

When i deploy my java-ee-8 application to WildFly 21.0.2 server (also tried 19.1.0) i can not access xhtml page. I get 404 error code. When i deploy to Apache TomEE 8.0.5 web profile, page is accessible. Both servers are compatible with java-ee-8 and started successfully. No errors in console nor logs.

No configuration were done to the servers, i just added them to Eclipse and started. Same project was deployed. Does anyone know where could be the problem? I want to deploy my app to WildFly, not TomEE.

TomEE starting log, also with accessing the page: https://textuploader.com/185ql

WildFly starting log (nothing in console when trying to access the page): https://textuploader.com/185qc

project structure:

Project structure

pom.xml:

<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>vis</groupId>
    <artifactId>eshop-web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

web.xml:

<?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_4_0.xsd"
    version="4.0">
    <display-name>eshop-web</display-name>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

index.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions"
    xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Hello World</title>
</head>

<body style="background-color: lightgrey;">
    <h2>Hello World</h2>
</body>
</html>

project facets:

Project facets

Url i am trying to access is this: http://localhost:8080/eshop-web/index.xhtml Also tried: http://localhost:8080/index.xhtml, http://localhost:8080/webapp/index.xhtml, but still the page can not be found. I think it might be project configuration bug.

Upvotes: 1

Views: 2871

Answers (1)

BalusC
BalusC

Reputation: 1108557

URL I am trying to access is this: http://localhost:8080/eshop-web/index.xhtml

The context path is wrong.

In case of WildFly, the actually used context path is logged with key WFLYUT0021.

The following line is found in your WildFly startup log when searching for this key:

23:00:04,727 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 81) WFLYUT0021: Registered web context: '/javaee-test-0.0.1-SNAPSHOT' for server 'default-server'

So, adjust the URL accordingly: http://localhost:8080/javaee-test-0.0.1-SNAPSHOT/index.xhtml

Upvotes: 1

Related Questions