I am trying to set up a basic embedded Tomcat server and am unable to get the Tomcat server to run.
public class Main {
public static void main(String[] args) throws LifecycleException {
Tomcat tomcat = new Tomcat();
tomcat.setPort(8888);
tomcat.start();
tomcat.getServer().await();
}
}
Running this java app in Eclipse provides the output:
June 19, 2019 12:00:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
And then waits until I hit stop, as expected, but when I run curl localhost:8888
in the terminal, i get curl: (7) Failed connect to localhost:8888; Connection refused.
I've followed this tutorial exactly, but I cannot seem to get the server to actually run. Also, netstat -nlt
does not show the port 8888
being open.
My build.gradle
has a single dependency:
implementation 'org.apache.tomcat.embed:tomcat-embed-core:9.0.21'
Is there something I'm missing here?