title: How to run Liferay 7.1 as Windows service?
body: <p>I can run the portal fine when executing startup.bat. But when I tried to run it as service, following the steps in one of the answer in here: <a href="https://stackoverflow.com/questions/24119318/install-liferay-as-windows-2012r2-service">Install Liferay as Windows 2012R2 service</a> I receive java.lang.NullPointerException error
  I used tomcat 9 instead of 7 (as in the link)</p>
  
  <p>Java settings in tomcat9w.exe as per below</p>
  
  <p>Java virtual machine: </p>
  
  <pre><code>C:\Program Files\Java\jdk1.8.0_181\jre\bin\server\jvm.dll
  </code></pre>
  
  <p>Java Classpath: </p>
  
  <pre><code>D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6\bin\bootstrap.jar;D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6\bin\tomcat-juli.jar
  </code></pre>
  
  <p>Java Options:</p>
  
  <pre><code>-Dcatalina.home=D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6
  -Dcatalina.base=D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6
  -Djava.io.tmpdir=D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6\temp
  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
  -Djava.util.logging.config.file=D:\liferay-dxp-7.1.10-ga1\tomcat-9.0.6\conf\logging.properties
  -Dfile.encoding=UTF8
  -Djava.net.preferIPv4Stack=true
  -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false
  -Duser.timezone=GMT
  -Xms512m
  -Xmx10240m
  -XX:MaxPermSize=16384m
  -XX:MaxMetaspaceSize=16384m
  </code></pre>
  
  <p>Java 9 Options</p>
  
  <pre><code>--add-opens=java.base/java.lang=ALL-UNNAMED
  --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
  </code></pre>
  
  <p>Initial memory pool: 10240 MB</p>
  
  <p>Maximum memory pool: 24000 MB</p>
  
  <p>Thread stack size: 512 KB</p>
  
  <p>Entries from Liferay log file</p>
  
  <pre><code>2019-02-12 03:55:26.465 INFO  [main][HikariDataSource:95] HikariPool-1 - Starting...
  2019-02-12 03:55:27.558 INFO  [main][HikariDataSource:107] HikariPool-1 - Start completed.
  2019-02-12 03:55:27.574 INFO  [main][DialectDetector:77] Determine dialect for Microsoft SQL Server 13.0
  2019-02-12 03:55:28.011 INFO  [main][DialectDetector:155] Found dialect org.hibernate.dialect.SQLServerDialect
  2019-02-12 03:55:31.621 INFO  [main][HikariDataSource:95] HikariPool-2 - Starting...
  2019-02-12 03:55:31.652 INFO  [main][HikariDataSource:107] HikariPool-2 - Start completed.
  2019-02-12 03:55:32.574 INFO  [main][BundleStartStopLogger:35] STARTED org.eclipse.osgi_3.10.200.v20150831-0856 [0]
  2019-02-12 03:55:32.761 INFO  [Start Level: Equinox Container: d09fc806-7a2e-0019-1de8-abaf0d99730c][BundleStartStopLogger:35] STARTED com.liferay.util.taglib_3.1.3 [2]
  ....&lt;i truncated because too long&gt;...
  com.liferay.portal.social.activity.extender_1.0.1 [48]
  2019-02-12 03:55:36.793 INFO  [Start Level: Equinox Container: d09fc806-7a2e-0019-1de8-abaf0d99730c][DefaultLPKGDeployer:307] Start refreshing uninstalled orphan bundles
  2019-02-12 03:55:36.793 INFO  [Start Level: Equinox Container: d09fc806-7a2e-0019-1de8-abaf0d99730c][DefaultLPKGDeployer:315] Finished refreshing uninstalled orphan bundles
  2019-02-12 03:55:38.308 INFO  [Start Level: Equinox Container: d09fc806-7a2e-0019-1de8-abaf0d99730c][BundleStartStopLogger:35] STARTED com.liferay.portal.target.platform.indexer.impl_1.0.1 [49]
  2019-02-12 03:55:38.324 INFO  [Start Level: Equinox Container: d09fc806-7a2e-0019-1de8-abaf0d99730c][BundleStartStopLogger:35] STARTED org.apache.felix.dependencymanager.shell_3.2.0 [50]
  2019-02-12 03:55:38.590 ERROR [main][PortalContextLoaderListener:114] java.lang.NullPointerException
  java.lang.NullPointerException
      at com.liferay.portal.kernel.servlet.DirectServletRegistryUtil.clearServlets(DirectServletRegistryUtil.java:27)
      at com.liferay.portal.spring.context.PortalContextLoaderListener.contextDestroyed(PortalContextLoaderListener.java:135)
      at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4626)
      at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5263)
      at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:187)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:742)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:718)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:703)
      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
      at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1840)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
      at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
      at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:525)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:424)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1586)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:308)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
      at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
      at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:966)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
      at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
  2019-02-12 03:55:38.605 ERROR [main][PortalContextLoaderListener:114] java.lang.NullPointerException
  java.lang.NullPointerException
      at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.reset(HotDeployUtil.java:53)
      at com.liferay.portal.spring.context.PortalContextLoaderListener.contextDestroyed(PortalContextLoaderListener.java:142)
      at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4626)
      at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5263)
      at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:257)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:187)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:742)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:718)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:703)
      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
      at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1840)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
      at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
      at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:525)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:424)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1586)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:308)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
      at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
      at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:966)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
      at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
  2019-02-12 03:55:38.605 ERROR [main][PortalBeanLocatorUtil:109] BeanLocator is null
  </code></pre>
  
  <p>Entries from tomcat stderr file are here: <a href="https://pastebin.com/TjgAjubq" rel="nofollow noreferrer">https://pastebin.com/TjgAjubq</a></p>