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

Maven构建报错:jaxb-xjc的META-INF/versions/9路径无效原因排查

问题排查:Maven构建JAXB2插件报错“不是有效文件名”

使用Maven 3.8.6(搭配JDK 11.0.15)构建项目时,配置了org.codehaus.mojo:jaxb2-maven-plugin:2.4执行xjc目标,构建时报错:file:\D:\m2repository\org\glassfish\jaxb\jaxb-xjc\2.3.2\jaxb-xjc-2.3.2.jar!\META-INF\versions\9不是有效文件名,以下是排查分析及解决办法。

环境信息

mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: D:\Java\apache-maven-3.8.6
Java version: 11.0.15, vendor: Oracle Corporation, runtime: D:\Java\jdk-11.0.15
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

项目插件配置

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>${jaxb2-maven-plugin.version}</version>
            <executions>
                <execution>
                    <id>xjc-beeline</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <packageName>com.openpayment.provider.beeline.model</packageName>
                        <sources>
                            <source>src/main/resources/schema/beeline.xsd</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
            <!--hack https://github.com/mojohaus/jaxb2-maven-plugin/issues/43-->
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jaxb</groupId>
                    <artifactId>jaxb-xjc</artifactId>
                    <version>${jaxb-xjc.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.sun.activation</groupId>
                    <artifactId>jakarta.activation</artifactId>
                    <version>${jakarta.activation.property}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

错误信息

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.403 s
[INFO] Finished at: 2023-04-09T19:21:09+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.4:xjc (xjc-beeline) on project beeline-provider-impl: "file:\D:\m2repository\org\glassfish\jaxb\jaxb-xjc\2.3.2\jaxb-xjc-2.3.2.jar!\META-INF\versions\9" is not a valid file name: {1}: Invalid file path -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :beeline-provider-impl

报错原因及解决办法

  • 核心原因:jaxb-xjc 2.3.2版本包含JDK 9+的多版本字节码支持(即META-INF/versions/9目录),而jaxb2-maven-plugin 2.4在Windows系统下的路径处理逻辑存在缺陷,无法正确识别Jar包内的这种多版本目录路径,导致文件名有效性校验失败。
  • 解决办法1:升级插件版本
    将jaxb2-maven-plugin升级到2.5.0及以上版本,该版本已修复Windows系统下的多版本路径兼容问题。升级后可移除插件内手动指定的jaxb-xjc依赖,新版插件会自动适配兼容的依赖版本。
  • 解决办法2:降低jaxb-xjc版本
    若无法升级插件,可将jaxb-xjc版本降至2.3.0,该版本不包含JDK 9+的多版本目录结构,避免路径识别错误。同时需确保jakarta.activation依赖版本与jaxb-xjc 2.3.0兼容。
  • 补充操作:清理本地Maven仓库中jaxb-xjc 2.3.2的缓存目录(D:\m2repository\org\glassfish\jaxb\jaxb-xjc\2.3.2),重新执行构建命令,避免缓存文件损坏或残留导致的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 00:47:52