@Override public File getCatalinaHome() { if (service != null) { Server s = service.getServer(); if (s != null) { File base = s.getCatalinaHome(); if (base != null) { return base; } } } // Fall-back return super.getCatalinaHome(); }
@Override public void stop() { if (tomcat == null) { return; } try { tomcat.stop(); File workDirectory = Paths.get(tomcat.getServer().getCatalinaHome().getAbsolutePath(), "work").toFile(); FileUtils.deleteDirectory(workDirectory); tomcat.destroy(); } catch (LifecycleException | IOException e) { throw new RuntimeServiceException(e); } }
@Override public File getCatalinaHome() { if (service != null) { Server s = service.getServer(); if (s != null) { File base = s.getCatalinaHome(); if (base != null) { return base; } } } // Fall-back return super.getCatalinaHome(); }
server.getCatalinaHome().getPath());
public static void startServer(int tomcatPort, String contextPath, String servletName, Servlet servlet, String servletPattern) throws LifecycleException, IOException { List<String> relativeFolders = new ArrayList<>(); relativeFolders.add("src"); relativeFolders.add("main"); relativeFolders.add("webapp"); tomcat = new Tomcat(); tomcat.setBaseDir("."); tomcat.setPort(tomcatPort); // copy src/main/webapp to webapps/src/main/webapp baseDir = tomcat.getServer().getCatalinaHome().toPath(); Path sourcePath = baseDir.getParent().resolve("server"); webappsPath = baseDir.resolve("webapps"); destinationPath = webappsPath; for (String folder : relativeFolders) { sourcePath = sourcePath.resolve(folder); destinationPath = destinationPath.resolve(folder); } FileUtils.copyDirectory(sourcePath.toFile(), destinationPath.toFile()); Path relativePath = webappsPath.relativize(destinationPath); /* There needs to be a symlink to the current dir named 'webapps' */ context = tomcat.addContext(contextPath, relativePath.toString()); tomcat.addServlet(contextPath, servletName, servlet); context.addServletMappingDecoded(servletPattern, servletName); tomcat.init(); tomcat.start(); }
server.getCatalinaHome().getPath());
server.getCatalinaHome().getPath());