Search code examples
javajax-rsjava-ee-7wildfly-swarmundertowjaxrsserver

Wildfly-swarm: cannot access jax-rs resource (404 Not found)


I want to give wildfly-swarm a try. I created a project with Jax-rs fraction and a simple hello world resource. I ran it but I got 404 Not Found.

Here's my pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.aca.studies</groupId>
<artifactId>swarm</artifactId>
<version>1.0</version>

<properties>
    <version.wildfly-swarm>2017.7.0</version.wildfly-swarm>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>wildfly-swarm-plugin</artifactId>
            <version>${version.wildfly-swarm}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>package</goal>
                    </goals>
                </execution>
                <execution>
                    <id>start</id>
                </execution>
                <execution>
                    <id>stop</id>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>jaxrs</artifactId>
        <version>${version.wildfly-swarm}</version>
    </dependency>
</dependencies>

And here's my Jax-rs resource

package org.aca.studies;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/app")
public class Resource {

  @GET
  @Path("/greet")
  @Produces("text/html")
  public String greet() {
    return System.currentTimeMillis() + "";
  }
}

As you can see it is very simple. Maybe I'm missing something. I did not add a @ApplicationPath annotated class because according to the documentation (https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/common/jax-rs.html) this fraction adds one by default. Another thing I picked up from the examples on GitHub (https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/jaxrs/jaxrs) was that:

Since WildFly Swarm apps tend to support one deployment per executable, it automatically adds a jboss-web.xml to the deployment if it doesn't already exist. This is used to bind the deployment to the root of the web-server, instead of using the .war's own name as the application context.

So that's why I'm trying to access my resource from http://localhost:8080/app/greet


Solution

  • From your pom I think the issue is that you don't have <packaging>war</packaging> present which means a JAR is created instead.

    If you change Maven packaging to WAR then it should be fine