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

OpenLiberty中Maven过滤server.xml失效及服务异常问题求助

问题分析与解决方案

为什么普通Maven资源过滤配置不生效?

Open Liberty的liberty-maven-plugin有独立的配置文件加载逻辑,默认会直接读取src/main/liberty/config目录下的文件,不会经过Maven标准的<resources>资源处理流程。因此你添加的通用资源过滤配置无法作用于该目录下的server.xml。

正确实现server.xml的Maven变量替换

步骤1:配置liberty-maven-plugin开启过滤

在pom.xml的liberty-maven-plugin配置中,添加<configurations>节点,指定对server.xml启用过滤:

<plugin>
    <groupId>io.openliberty.tools</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>3.9.1</version> <!-- 使用最新稳定版本 -->
    <configuration>
        <!-- 开启server.xml的变量过滤 -->
        <configurations>
            <configuration>
                <file>src/main/liberty/config/server.xml</file>
                <filtering>true</filtering>
            </configuration>
        </configurations>
        <!-- 配置Open Liberty运行时版本(需支持所用特性) -->
        <runtimeArtifact>
            <groupId>io.openliberty</groupId>
            <artifactId>openliberty-runtime</artifactId>
            <version>24.0.0.3</version> <!-- 支持Jakarta EE 10的版本 -->
            <type>zip</type>
        </runtimeArtifact>
    </configuration>
</plugin>

步骤2:定义需要替换的Maven变量

在pom.xml的<properties>节点中声明server.xml里用到的变量:

<properties>
    <default.http.port>9080</default.http.port>
    <default.https.port>9443</default.https.port>
    <app.context.root>/LibertyProject</app.context.root>
</properties>

步骤3:移除无效的通用资源配置

删除之前添加的<build><resources>配置,避免冲突:

<!-- 移除这段无效配置 -->
<!--
<build>
    <resources>
        <resource>
            <directory>src/main/liberty/config</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>
-->

解决特性找不到的错误

你遇到的CWWKF0001E错误是因为所用Open Liberty版本不支持restfulWS-3.1和jsonb-3.0特性——这两个特性属于Jakarta EE 10规范,需要Open Liberty 22.0.0.12及以上版本。确保上述runtimeArtifact中的版本满足要求即可解决。

验证修复

执行mvn clean liberty:run,查看控制台输出:

  • 确认server.xml中的变量已被替换(如httpPort显示为9080)
  • 确认特性加载成功,无CWWKF0001E错误
  • 访问http://localhost:9080/LibertyProject/system/properties验证服务可正常访问

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 09:27:34