source: src/test/java/geniusweb/clienttest/EmbeddedTomcat.java@ 25

Last change on this file since 25 was 25, checked in by bart, 4 years ago

Fixed memory leak. MOPAC2. removed jcenter build dependencies

File size: 1.4 KB
Line 
1package geniusweb.clienttest;
2
3import java.io.File;
4
5import org.apache.catalina.LifecycleException;
6import org.apache.catalina.startup.Tomcat;
7
8class EmbeddedTomcat {
9 private Tomcat tomcat = new Tomcat();
10
11 public void start() {
12 try {
13 // If I don't want to copy files around then the base directory must be '.'
14 String baseDir = ".";
15 tomcat.setPort(8080);
16 tomcat.setBaseDir(baseDir);
17 tomcat.getHost().setAppBase(baseDir);
18 tomcat.getHost().setDeployOnStartup(true);
19 tomcat.getHost().setAutoDeploy(true);
20 tomcat.start();
21 } catch (LifecycleException e) {
22 throw new RuntimeException(e);
23 }
24 }
25
26 public void stop() {
27 try {
28 tomcat.stop();
29 tomcat.destroy();
30 // Tomcat creates a work folder where the temporary files are stored
31 // FileUtils.deleteDirectory(new File("work"));
32 } catch (LifecycleException e) {
33 throw new RuntimeException(e);
34// } catch (IOException e) {
35// throw new RuntimeException(e);
36 }
37 }
38
39 public void deploy(String appName) {
40 // tomcat.addWebapp(tomcat.getHost(), "/" + appName, new
41 // File("src/main/webapp").getAbsolutePath());
42 tomcat.addWebapp(tomcat.getHost(), "/" + appName, new File("src/main/webapp").getAbsolutePath());
43 }
44
45 public String getApplicationUrl(String appName) {
46 return String.format("http://%s:%d/%s", tomcat.getHost().getName(), tomcat.getConnector().getLocalPort(),
47 appName);
48 }
49}
Note: See TracBrowser for help on using the repository browser.