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

WildFly 20.0.1部署Java Web应用报错:找不到指定模块

解决WildFly部署EAR时找不到JAR模块的问题

问题背景

尝试部署一个关联WAR和JAR文件的Java Web应用,主模块为EAR包,已在application.xml中配置模块关联。启动WildFly 20.0.1服务器时,尽管模块文件已在部署目录,仍提示找不到s2-commons-2.28.1.jar模块。

环境信息

  • JDK 8
  • Maven 3.8.0
  • WildFly 20.0.1.Final

application.xml配置内容

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_7.xsd"
             version="7">

    <!-- Descripción de la aplicación empresarial -->
    <display-name>s2-vital-ear</display-name>

    <!-- Módulo JAR -->
    <module>
        <java>s2-commons-2.28.1.jar</java>
    </module>


    <!-- Módulo WAR -->
    <module>
        <web>
            <web-uri>s2-enlace-web-2.28.1.war</web-uri>
            <context-root>/s2-vital-web</context-root>
        </web>
    </module>

</application>

报错信息

17:26:40,495 INFO  [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.4.1.Final (Apache CXF 3.3.6)
17:26:40,522 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."s2-vital-ear-2.28.1.ear".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."s2-vital-ear-2.28.1.ear".STRUCTURE: WFLYSRV0153: Failed to process phase STRUCTURE of deployment "s2-vital-ear-2.28.1.ear"
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
        at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
        at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0031: Unable to process modules in application.xml for EAR ["/C:/Users/andreacamacho/instaladores/wildfly-20.0.1.Final/bin/content/s2-vital-ear-2.28.1.ear"], module file s2-commons-2.28.1.jar not found
        at org.jboss.as.ee.structure.EarStructureProcessor.deploy(EarStructureProcessor.java:187)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
        ... 8 more

解决方案

1. 确认EAR包内部文件结构

WildFly会从EAR包内部查找配置的模块文件,而非部署目录的外部文件。必须确保s2-commons-2.28.1.jar和s2-enlace-web-2.28.1.war直接放在EAR包的根目录下,正确结构如下:

s2-vital-ear-2.28.1.ear/
├── META-INF/
│   └── application.xml
├── s2-commons-2.28.1.jar
└── s2-enlace-web-2.28.1.war

2. 验证application.xml的路径与文件名匹配

  • 确保application.xml位于EAR包的META-INF目录下,路径不能错误。
  • 检查配置中的JAR/WAR文件名与EAR内实际文件名完全一致(包括版本号,Linux环境下需严格匹配大小写)。

3. 修正Maven EAR插件打包配置

如果用Maven打包,需在EAR模块的pom.xml中正确声明模块,确保依赖的JAR/WAR被打包进EAR:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>3.2.0</version>
    <configuration>
        <version>7</version>
        <modules>
            <jarModule>
                <groupId>你的项目groupId</groupId>
                <artifactId>s2-commons</artifactId>
                <version>2.28.1</version>
                <bundleFileName>s2-commons-2.28.1.jar</bundleFileName>
            </jarModule>
            <webModule>
                <groupId>你的项目groupId</groupId>
                <artifactId>s2-enlace-web</artifactId>
                <version>2.28.1</version>
                <bundleFileName>s2-enlace-web-2.28.1.war</bundleFileName>
                <contextRoot>/s2-vital-web</contextRoot>
            </webModule>
        </modules>
    </configuration>
</plugin>

若将JAR放在EAR的lib子目录,需在application.xml中添加library-directory配置:

<application ...>
    <library-directory>lib</library-directory>
    <!-- 原有模块配置 -->
</application>

4. 清理并重新构建部署包

执行Maven命令清理旧构建产物,重新打包,避免缓存问题:

mvn clean install

将新生成的EAR包重新部署到WildFly。

5. 检查WildFly解压后的目录

WildFly会将EAR包解压到bin/content目录(如报错中的/C:/Users/andreacamacho/instaladores/wildfly-20.0.1.Final/bin/content/s2-vital-ear-2.28.1.ear),直接查看该目录下是否存在s2-commons-2.28.1.jar。若不存在,说明打包时未将该JAR包含进EAR。


内容的提问来源于stack exchange,提问作者ANDREA CAROLINA CAMACHO JULIO

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 21:14:52