没有容器Java怎么不停止_如何使用Java启动和停止Tomcat容器?

小编典典

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

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

API完成。

要启动Tomcat容器并部署您的战争,您可以在setUp()方法中执行以下操作:

// (1) Optional step to install the container from a URL pointing to its distribution

Installer 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 container

LocalConfiguration 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 container

container.start();

并停止该tearDown()方法。

// (6) Stop the container

container.stop();

2020-06-16

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值