servlet是project项目下的一个module**, 没有这种结构的就不需要写进来**
不知道有没有获取当前模块路径的办法
public class Application { public static void main(String[] args) throws Exception { // 启动Tomcat: Tomcat tomcat = new Tomcat(); tomcat.setPort(Integer.getInteger("port", 8080)); tomcat.getConnector(); // 创建webapp: System.out.println(new File("servlet/src/main/webapp").getAbsolutePath());
Context ctx = tomcat.addWebapp("", new File("servlet/src/main/webapp").getAbsolutePath()); WebResourceRoot resources = new StandardRoot(ctx); resources.addPreResources( new DirResourceSet(resources, "/WEB-INF/classes", new File("servlet/target/classes").getAbsolutePath(), "/")); ctx.setResources(resources); tomcat.start(); tomcat.getServer().await(); } }
Sign in to make a reply
净净一隅
servlet是project项目下的一个module**, 没有这种结构的就不需要写进来**
不知道有没有获取当前模块路径的办法
public class Application {
public static void main(String[] args) throws Exception {
// 启动Tomcat:
Tomcat tomcat = new Tomcat();
tomcat.setPort(Integer.getInteger("port", 8080));
tomcat.getConnector();
// 创建webapp:
System.out.println(new File("servlet/src/main/webapp").getAbsolutePath());
Context ctx = tomcat.addWebapp("", new File("servlet/src/main/webapp").getAbsolutePath());
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(
new DirResourceSet(resources, "/WEB-INF/classes", new File("servlet/target/classes").getAbsolutePath(), "/"));
ctx.setResources(resources);
tomcat.start();
tomcat.getServer().await();
}
}