使用Cargo Maven3插件远程部署至Tomcat 10时遭遇“No container defined”错误
问题:使用Codehaus Cargo Maven3插件部署到远程Tomcat10时出现“No container defined”错误
我尝试用Codehaus Cargo Maven3插件将WAR制品部署到远程Tomcat10实例,但执行redeploy目标时遇到了“No container defined”的错误,插件自动默认用了Jetty9x容器,导致构建失败。
我的插件配置如下:
<plugin> <artifactId>cargo-maven3-plugin</artifactId> <version>1.10.2</version> <configuration> <!-- Container configuration --> <container> <containerId>tomcat10x</containerId> <type>remote</type> </container> <!-- Configuration to use with the container (which will also configure the deployer) --> <configuration> <type>runtime</type> <properties> <cargo.hostname>${remote.hostname}</cargo.hostname> <cargo.protocol>${remote.protocol}</cargo.protocol> <cargo.servlet.port>${remote.port}</cargo.servlet.port> <cargo.tomcat.manager.url>${remote.uri}</cargo.tomcat.manager.url> <cargo.remote.username>${remote.user}</cargo.remote.username> <cargo.remote.password>${remote.pass}</cargo.remote.password> </properties> </configuration> <!-- Deployables configuration --> <deployables> <deployable> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <type>war</type> <properties> <context>${war.name}</context> </properties> </deployable> </deployables> </configuration> </plugin>
报错信息:
[INFO] --- cargo-maven3-plugin:1.10.2:redeploy (default-cli) @ beletrik --- [INFO] No container defined, using a default [jetty9x, installed] container [INFO] [DeployerRedeployMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-jetty:jar:1.10.2 for container jetty9x [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
请问是否必须定义容器?应在何处进行定义?
解决方案
哎,你这里其实踩了一个XML配置的小坑!你已经定义了<container>节点,但因为外层<configuration>里嵌套了另一个同名的<configuration>,导致Cargo插件的解析逻辑混乱,直接忽略了你设置的Tomcat容器,转而用了默认的Jetty,这就是报错的原因。
具体修复方法
你需要把内层那个<configuration>改成<deployer>——这才是Cargo插件里存放远程部署连接参数的正确节点。修改后的配置如下:
<plugin> <artifactId>cargo-maven3-plugin</artifactId> <version>1.10.2</version> <configuration> <!-- 容器定义:明确指定远程Tomcat10 --> <container> <containerId>tomcat10x</containerId> <type>remote</type> </container> <!-- 远程部署器的配置:替换原来嵌套的configuration --> <deployer> <type>remote</type> <properties> <cargo.hostname>${remote.hostname}</cargo.hostname> <cargo.protocol>${remote.protocol}</cargo.protocol> <cargo.servlet.port>${remote.port}</cargo.servlet.port> <cargo.tomcat.manager.url>${remote.uri}</cargo.tomcat.manager.url> <cargo.remote.username>${remote.user}</cargo.remote.username> <cargo.remote.password>${remote.pass}</cargo.remote.password> </properties> </deployer> <!-- 要部署的WAR包配置 --> <deployables> <deployable> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <type>war</type> <properties> <context>${war.name}</context> </properties> </deployable> </deployables> </configuration> </plugin>
关于你的问题
- 是否必须定义容器?:是的!尤其是远程部署场景,必须明确指定容器的
containerId和type,不然Cargo不知道该用哪种容器的部署逻辑,就会瞎用默认的Jetty。 - 在哪里定义?:就在插件的外层
<configuration>下直接放<container>节点就行,别嵌套在其他同名节点里,像上面的配置那样。
改完之后再跑mvn cargo:redeploy,应该就能正常连接远程Tomcat10部署你的WAR包了。
内容的提问来源于stack exchange,提问作者comodoro
相关产品推荐
相关产品推荐

