Search code examples
web-applicationswildfly-9

WildFly 9 deploying simple webapp but 404


I have a simple hello world webapp that when I run it in tomcat with the url http://localhost:8080/na/environment works fine; The same war in wildfly 9 does not work, I get a 404 error.

Googling it I found a WildFly project requires 2 files(beans.xml and jboss-web.xml), I just added to the project but still is not working.

My wildldFly admin console says the war is deployed and enabled

wildFly console

This is the structure of my project:

project structure

And the content of my file jboss-web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
 <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
  <context-root>/</context-root>
 </jboss-web>

The beans.xml is empty(still don't get what is its porpoise).

Finally, the code of my servlet(and only class) is:

@WebServlet(urlPatterns="/environment")
public class Environment extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException,
                                                       IOException {
    response.getWriter().append("Hello");
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException,
                                                        IOException {
    doGet(request, response);
    }



}

I tried using:

http://localhost:9990/na/environment/
http://localhost:9990/na.war/environment/
http://localhost:9990/environment/

Solution

  • If you want the context to be na you need to change your jboss-web.xml to use na as the root context.

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
        <context-root>/na</context-root>
    </jboss-web>   
    

    If you change the runtime name when you deploy that should also work. You could also override the <finalName>na</finalName> in your pom as well.