You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WildFly Swarm页面未找到错误及对应pom.xml文件说明

Fixing WildFly Swarm 404 Page Not Found Error

Hey there, let's break down why you're hitting that 404 with WildFly Swarm and how to fix it. Since your pom.xml got cut off mid-way, I’ll cover the most common culprits tied to your setup, plus fill in the gaps for a working configuration.

1. Ensure Your pom.xml Has Complete WildFly Swarm Dependencies

WildFly Swarm relies on "fractions" (modular dependencies) to enable specific features. If your pom is missing key fractions like the web server or JAX-RS support, your app won’t expose endpoints properly. Here’s what your full pom should include (matching your groupId/artifactId):

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>hu.javacity.app.buildingsofcities</groupId>
    <artifactId>city</artifactId>
    <name>WildFly Swarm Example</name>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging> <!-- Use war for web apps; jar works too for uberjars -->

    <!-- Import WildFly Swarm BOM to manage dependency versions -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>bom-all</artifactId>
                <version>2018.5.0</version> <!-- Use a stable Swarm version; adjust if needed -->
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!-- Core dependencies for web/JAX-RS -->
    <dependencies>
        <!-- Undertow web server fraction (required for any web app) -->
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>undertow</artifactId>
        </dependency>
        <!-- JAX-RS fraction if you're building REST endpoints -->
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>jaxrs</artifactId>
        </dependency>
    </dependencies>

    <!-- WildFly Swarm plugin to build executable uberjar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <version>2018.5.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2. Verify Your Application’s Endpoint Mapping

A common 404 cause is missing or incorrect routing annotations:

  • Add an @ApplicationPath class to define your app’s base URL:
    import javax.ws.rs.ApplicationPath;
    import javax.ws.rs.core.Application;
    
    @ApplicationPath("/api") // All endpoints will be under http://localhost:8080/api
    public class CityApplication extends Application {}
    
  • Annotate your resource classes correctly:
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;
    
    @Path("/buildings") // Full path: /api/buildings
    public class BuildingResource {
        @GET
        @Produces(MediaType.TEXT_PLAIN)
        public String getBuildings() {
            return "List of city buildings";
        }
    }
    

3. Check Your Startup & Access Paths

  • Launch the app correctly: Build with mvn clean package, then run the executable uberjar:
    java -jar target/city-1.0.0-SNAPSHOT-swarm.jar
    
  • Use the full correct URL: By default, WildFly Swarm uses your artifactId as the context root. So if you didn’t set @ApplicationPath, your endpoint would be:
    http://localhost:8080/city/buildings
    If you did set @ApplicationPath("/api"), it’s:
    http://localhost:8080/city/api/buildings

4. Quick Troubleshooting Checks

  • Confirm the server starts without errors (check console logs for deployment failures).
  • Verify you’re using the correct port (default is 8080; if you changed it, adjust your URL).
  • If you’re using a plain servlet instead of JAX-RS, ensure your web.xml or @WebServlet annotation maps to the right path.

内容的提问来源于stack exchange,提问作者Deylath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:24:04