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

Wildfly Swarm Uber Jar因未使用的依赖缺失启动失败求助

Fixing WildFly Swarm Hollow Jar Startup Failure Due to Missing Unused Dependencies

Hey there, I’ve run into this exact issue when migrating from monolithic WildFly to WildFly Swarm, so I know how frustrating it can be. The core problem here is that WildFly Swarm’s shrinkwrap tooling aggressively prunes dependencies that aren’t directly referenced in your application code—but some dependencies (especially those loaded via reflection or required by the container runtime) are still needed at startup. Here’s how to fix it:

1. Explicitly Include Required WildFly Swarm Fractions

WildFly Swarm uses "fractions" to package only the necessary container components. If your app relies on Java EE features that aren’t being auto-detected, you need to add the corresponding fractions to your pom.xml:

<dependencies>
    <!-- Example: Add EJB fraction if your app uses EJBs -->
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>ejb</artifactId>
        <version>${wildfly-swarm.version}</version>
    </dependency>
    <!-- Add other fractions like jpa, jaxrs, etc., as needed -->
</dependencies>

Fractions automatically pull in all transitive dependencies required for that feature, so this is the most reliable way to avoid missing runtime components.

2. Handle Reflection-Loaded Classes with Jandex Indexing

If your app uses reflection (e.g., Class.forName(), CDI proxies, or frameworks like Hibernate that load entities dynamically), Swarm’s default classpath scanning might miss these classes. To fix this:

  • Add the Jandex Maven plugin to your build to generate a class index:
<build>
    <plugins>
        <plugin>
            <groupId>org.jboss.jandex</groupId>
            <artifactId>jandex-maven-plugin</artifactId>
            <version>1.2.3</version>
            <executions>
                <execution>
                    <id>make-index</id>
                    <goals>
                        <goal>jandex</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
  • Alternatively, explicitly specify packages to include in your project-defaults.yml (in src/main/resources):
swarm:
  deployment:
    myapp.war:
      jandex:
        include:
          - com.yourcompany.yourpackage

3. Force Include Missing Dependencies

If you’ve identified a specific dependency that’s being pruned but is required, you can force Swarm to include it by declaring it as a direct dependency with scope=compile (even if your code doesn’t reference it directly):

<dependency>
    <groupId>com.example</groupId>
    <artifactId>missing-dependency</artifactId>
    <version>1.0.0</version>
    <scope>compile</scope>
</dependency>

4. Debug the Dependency Tree

To figure out exactly which dependencies are missing, run the Maven dependency tree command to see what’s being excluded:

mvn dependency:tree -Dverbose -Dincludes=com.example:missing-dependency

This will show you if the dependency is being excluded by a transitive dependency rule, and you can adjust your pom.xml to override that exclusion.

5. Verify Your Hollow Jar Build

When creating the hollow jar, make sure you’re including all necessary fractions and dependencies in the base hollow artifact. If you’re using the Swarm Maven plugin to build the hollow jar, double-check your plugin configuration:

<plugin>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>wildfly-swarm-plugin</artifactId>
    <version>${wildfly-swarm.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>package</goal>
            </goals>
            <configuration>
                <hollow>true</hollow>
                <!-- Include any additional modules or fractions here -->
                <modules>
                    <module>org.wildfly.swarm:ejb</module>
                </modules>
            </configuration>
        </execution>
    </executions>
</plugin>

Start with checking the fractions first—this is the most common fix for this issue. Let me know if you need more specifics for your particular stack!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 10:09:45