Apache Tomcat getting stuck while starting

Lately, I was working on Tomcat 9 and encountered an issue. It was getting stuck at the following stage during startup.

22-Sep-2018 03:06:00.347 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/root/apache-tomcat-9.0.12/temp
22-Sep-2018 03:06:00.347 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
22-Sep-2018 03:06:00.601 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
22-Sep-2018 03:06:00.629 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Sep-2018 03:06:00.650 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
22-Sep-2018 03:06:00.651 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Sep-2018 03:06:00.665 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1341 ms
22-Sep-2018 03:06:00.738 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
22-Sep-2018 03:06:00.738 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.12
22-Sep-2018 03:06:00.766 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/root/apache-tomcat-9.0.12/webapps/ROOT]

Are you also having the same issue?

Usually, this happens on VM and here is how you can fix this. Take a backup of a file before modifying and if feasible, test in a non-production environment.

  • Go to Tomcat installation folder and then bin
  • Open catalina.sh using the vi editor
  • Search for JAVA_OPTS and add the following
-Djava.security.egd=file:/dev/./urandom

For example, I added it here.

JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Djava.security.egd=file:/dev/./urandom"
  • Save the file and restart Tomcat

Look at the catalina.out file and it should be started.

22-Sep-2018 05:44:26.898 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/root/apache-tomcat-9.0.12/webapps/manager] has finished in [53] ms
22-Sep-2018 05:44:26.909 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
22-Sep-2018 05:44:26.924 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
22-Sep-2018 05:44:26.931 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 2085 ms

This simple trick has helped me, and I hope you too!

If you are learning or curious to learn more about Tomcat then check out this beginner to the advanced course.