栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Java启动和停止Tomcat容器?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Java启动和停止Tomcat容器?

因此,是否可以使用Java语句启动和停止容器?

您的用例看起来很奇怪(必须在两次测试之间重新启动容器),但我们不要讨论这个。要回答您的问题,可以,可以使用Cargo的Java
API完成。

要启动Tomcat容器并部署您的战争,您可以在

setUp()
方法中执行以下操作:

// (1) Optional step to install the container from a URL pointing to its distributionInstaller installer = new ZipURLInstaller(new URL("http://www.apache.org/dist/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip"));installer.install();// (2) Create the Cargo Container instance wrapping our physical containerLocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()        .createConfiguration("tomcat6x"), ContainerType.INSTALLED, ConfigurationType.STANDALONE);container = (InstalledLocalContainer) new DefaultContainerFactory()        .createContainer("tomcat6x", ContainerType.INSTALLED, configuration);container.setHome(installer.getHome());// (3) Statically deploy some WAR (optional)WAR deployable = new WAR("./webapp-testing-webapp/target/webapp-testing-webapp-1.0.war");deployable.setContext("ROOT");configuration.addDeployable(deployable);// (4) Start the containercontainer.start();

并停止该

tearDown()
方法。

// (6) Stop the containercontainer.stop();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/468909.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号