Java 嵌入式Tomcat不会启动
我正在尝试在Tomcat的嵌入式实例上运行web应用程序。所以我把它放在webapps目录下,运行以下代码Java 嵌入式Tomcat不会启动,java,tomcat,Java,Tomcat,我正在尝试在Tomcat的嵌入式实例上运行web应用程序。所以我把它放在webapps目录下,运行以下代码 public static void main(String[] args) throws Exception { String currentDir = new File(".").getCanonicalPath(); String appBase = currentDir + File.separatorChar + "webapps"; S
public static void main(String[] args) throws Exception {
String currentDir = new File(".").getCanonicalPath();
String appBase = currentDir + File.separatorChar + "webapps";
System.out.println(appBase);
Integer port = 4040;
Tomcat tomcat = new Tomcat();
tomcat.setPort(port);
tomcat.setBaseDir(".");
tomcat.addWebapp("/myTools.war", appBase);
tomcat.setHostname("localhost");
tomcat.start();
while (true) {
Thread.sleep(999999999);
}
}
Tomcat实例似乎启动了(虽然我收到一些“无法获取/javax/servlet的url…”类型的警告,但我认为这是正常的)。但是,当我连接到localhost:4040或localhost:4040/myTools时,我只看到一个空白页(或Tomcat警告地址不存在)。我还尝试将war扩展到一个目录并使用
tomcat.addWebapp("/myTools", appBase);
但一切都没有改变。关于如何使其工作,有什么想法吗?请删除结尾处的(可怕的)无休止的while slope,并将其替换为:
tomcat.getServer().await();
是的,我一开始就是这样做的,我在无数次尝试中加入了无休止的努力,让它发挥作用!但我同意这很可怕。