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

如何解决Maven Moditect插件报错“Unable to derive module descriptor for *.jar”?

报错核心原因:poi-ooxml 依赖传递引入的 xalan 2.7.2 属于传统非模块化 Jar 包,包内的服务提供者配置和类路径结构不符合 Moditect 自动推导模块描述符的规则,导致生成失败。

方案1:无需保留xalan(推荐,大多数场景适用)

JDK 9及以上版本已经内置了默认的XSLT处理实现,绝大多数场景下不需要依赖第三方xalan包,直接排除poi-ooxml传递引入的xalan即可:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
        </exclusion>
    </exclusions>
</dependency>

修改后重新执行Moditect任务,不会再扫描xalan包,报错直接消失。

方案2:必须保留xalan功能

如果项目确实用到了xalan的专有特性,不能排除依赖,手动为xalan指定模块描述符,跳过Moditect的自动推导步骤即可:

  1. 修改依赖配置,排除poi内置的xalan后单独声明依赖,避免版本冲突
<!-- 排除poi传递引入的xalan -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- 单独引入xalan -->
<dependency>
    <groupId>xalan</groupId>
    <artifactId>xalan</artifactId>
    <version>2.7.2</version>
</dependency>
  1. 修改Moditect插件配置,优先为xalan手动指定模块信息,跳过自动推导:
<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0.RC1</version>
    <executions>
        <execution>
            <id>generate-module-info</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate-module-info</goal>
            </goals>
            <configuration>
                <modules>
                    <!-- 新增xalan的模块配置 -->
                    <module>
                        <artifact>
                            <groupId>xalan</groupId>
                            <artifactId>xalan</artifactId>
                            <version>2.7.2</version>
                        </artifact>
                        <moduleInfoSource>
                            module xalan {
                                requires java.xml;
                                requires jdk.xml.dom;
                                exports org.apache.xalan;
                                exports org.apache.xalan.extensions;
                                exports org.apache.xalan.lib;
                                exports org.apache.xalan.templates;
                                exports org.apache.xalan.transformer;
                                exports org.apache.xpath;
                                exports org.apache.xpath.compiler;
                                exports org.apache.xpath.functions;
                                exports org.apache.xpath.jaxp;
                                exports org.apache.xpath.objects;
                                exports org.apache.xpath.operations;
                                exports org.apache.xpath.patterns;
                                provides javax.xml.transform.TransformerFactory with org.apache.xalan.processor.TransformerFactoryImpl;
                            }
                        </moduleInfoSource>
                    </module>
                    <!-- 原来的poi-ooxml配置保留 -->
                    <module>
                        <artifact>
                            <groupId>org.apache.poi</groupId>
                            <artifactId>poi-ooxml</artifactId>
                            <version>5.0.0</version>
                        </artifact>
                    </module>
                </modules>
            </configuration>
        </execution>
    </executions>
</plugin>

注意事项

  • 上述moduleInfoSource中的exports内容可以根据项目实际用到的包精简,不需要全量导出所有包,减少模块暴露范围。
  • 如果运行时出现类找不到的报错,对应在xalan的模块配置中添加对应的exports语句即可。
    内容的提问来源于stack exchange,提问作者cegredev
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.16 09:36:05