使用cargo-maven2-plugin向Payara部署War包二次redeploy报错问题
问题原因
- 配置缺失必要参数:当前配置仅指定了 servlet 端口,未声明容器类型、远程主机地址、Payara 管理控制台的账号密码等核心参数。首次部署无历史应用时可以正常上传,第二次执行 redeploy 时,插件无法匹配到已部署的旧应用实例,undeploy 后状态重置异常触发空指针。
- 部署上下文未显式声明:插件默认使用 artifactId 作为应用上下文路径,若 Payara 侧存在残留部署记录、或者两次构建的 artifact 信息有变动,会导致插件无法定位到要替换的应用,触发空异常。
- 执行配置不完整:execution 块仅绑定了 pre-integration-test 阶段,未显式指定执行的 goal,1.7.16 版本的 cargo 插件会在重复执行时出现 goal 匹配混乱,执行逻辑不符合预期。
- 版本兼容问题:cargo-maven2-plugin 1.7.16 与 Payara 5.2020+ 版本的远程 redeploy 逻辑存在已知兼容缺陷,undeploy 操作完成后未正确重置部署状态就发起新部署请求,导致空指针报错。
解决方案
- 补全插件配置,补充容器类型、远程连接、认证参数,显式指定部署上下文,同时在 execution 中声明执行 goal,修改后的参考配置如下:
<profile> <id>payara-remote</id> <activation> <property> <name>deployAll</name> <value>true</value> </property> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.7.16</version> <configuration> <!-- 声明容器类型为Payara远程模式 --> <container> <containerId>payara</containerId> <type>remote</type> </container> <configuration> <properties> <cargo.hostname>你的Payara服务地址</cargo.hostname> <cargo.servlet.port>${servlet.port}</cargo.servlet.port> <!-- Payara管理控制台端口默认是4848 --> <cargo.remote.port>4848</cargo.remote.port> <cargo.remote.username>Payara管理账号</cargo.remote.username> <cargo.remote.password>Payara管理密码</cargo.remote.password> </properties> </configuration> <deployables> <deployable> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <type>war</type> <!-- 显式指定应用上下文路径 --> <properties> <context>你的应用上下文路径</context> </properties> </deployable> </deployables> </configuration> <executions> <execution> <id>deploy</id> <phase>pre-integration-test</phase> <!-- 显式指定执行redeploy目标 --> <goals> <goal>redeploy</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile>
- 若修改配置后仍报错,可将插件版本升级至1.9.12及以上,该版本已修复Payara远程redeploy的空指针兼容问题。
- 若不需要保留原有部署记录,可将执行goal替换为undeploy和deploy两个步骤,同时添加忽略undeploy失败的参数,避免首次执行无旧应用时报错:
<executions> <execution> <id>undeploy-old</id> <phase>pre-integration-test</phase> <goals> <goal>undeploy</goal> </goals> <configuration> <properties> <cargo.undeploy.ignoreFailure>true</cargo.undeploy.ignoreFailure> </properties> </configuration> </execution> <execution> <id>deploy-new</id> <phase>pre-integration-test</phase> <goals> <goal>deploy</goal> </goals> </execution> </executions>
内容的提问来源于stack exchange,提问作者user3773380
相关产品推荐
相关产品推荐

