title: javax.naming.NoInitialContextException: Need to specify class name in environment or system property Heroku deploy
body: <p>Im trying to deploy a java web app to heroku,
  I did all their steps from <a href="https://devcenter.heroku.com/articles/deploying-java-applications-with-the-heroku-maven-plugin" rel="nofollow noreferrer">https://devcenter.heroku.com/articles/deploying-java-applications-with-the-heroku-maven-plugin</a>, but when I try to open a page where I have data from db I am getting:</p>
  <pre><code>`javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
  2021-06-09T19:50:10.133124+00:00 app[web.1]:    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:673)
  2021-06-09T19:50:10.133124+00:00 app[web.1]:    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
  2021-06-09T19:50:10.133125+00:00 app[web.1]:    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
  2021-06-09T19:50:10.133125+00:00 app[web.1]:    at javax.naming.InitialContext.lookup(InitialContext.java:417)
  2021-06-09T19:50:10.133126+00:00 app[web.1]:    at listeners.JDBCContextListener.contextInitialized(JDBCContextListener.java:27)
  2021-06-09T19:50:10.133127+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4685)
  2021-06-09T19:50:10.133127+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
  2021-06-09T19:50:10.133127+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  2021-06-09T19:50:10.133128+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
  2021-06-09T19:50:10.133128+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
  2021-06-09T19:50:10.133128+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  2021-06-09T19:50:10.133129+00:00 app[web.1]:    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
  2021-06-09T19:50:10.133129+00:00 app[web.1]:    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
  2021-06-09T19:50:10.133130+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
  2021-06-09T19:50:10.133130+00:00 app[web.1]:    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
  2021-06-09T19:50:10.133130+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  2021-06-09T19:50:10.133131+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
  2021-06-09T19:50:10.133131+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
  2021-06-09T19:50:10.133132+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  2021-06-09T19:50:10.133132+00:00 app[web.1]:    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
  2021-06-09T19:50:10.133132+00:00 app[web.1]:    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
  2021-06-09T19:50:10.133133+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
  2021-06-09T19:50:10.133133+00:00 app[web.1]:    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
  2021-06-09T19:50:10.133134+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  2021-06-09T19:50:10.133134+00:00 app[web.1]:    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
  2021-06-09T19:50:10.133135+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  2021-06-09T19:50:10.133135+00:00 app[web.1]:    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
  2021-06-09T19:50:10.133135+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
  2021-06-09T19:50:10.133136+00:00 app[web.1]:    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:459)
  2021-06-09T19:50:10.133136+00:00 app[web.1]:    at webapp.runner.launch.Main.main(Main.java:289)`
  </code></pre>
  <p>It works well on my local machine. Please advise me.
  There is my pom.xml :</p>
  <pre><code>`&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.mycompany&lt;/groupId&gt;
      &lt;artifactId&gt;GrowUp&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;name&gt;GrowUp&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
      
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-util --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-util&lt;/artifactId&gt;
              &lt;version&gt;8.5.23&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.23&lt;/version&gt;
          &lt;/dependency&gt;
          
          &lt;!-- https://mvnrepository.com/artifact/com.ckeditor/ckeditor-java-core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.ckeditor&lt;/groupId&gt;
              &lt;artifactId&gt;ckeditor-java-core&lt;/artifactId&gt;
              &lt;version&gt;3.5.3&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;compilerArguments&gt;
                          &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                      &lt;/compilerArguments&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.heroku.sdk&lt;/groupId&gt;
                  &lt;artifactId&gt;heroku-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.0.3&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.6&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;validate&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;copy&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                              &lt;silent&gt;true&lt;/silent&gt;
                              &lt;artifactItems&gt;
                                  &lt;artifactItem&gt;
                                      &lt;groupId&gt;javax&lt;/groupId&gt;
                                      &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                      &lt;version&gt;7.0&lt;/version&gt;
                                      &lt;type&gt;jar&lt;/type&gt;
                                  &lt;/artifactItem&gt;
                              &lt;/artifactItems&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  `
  </code></pre>
  <p>There is my context.xml</p>
  <pre><code>`&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Context path=&quot;/GrowUp&quot;&gt;
  &lt;Resource auth=&quot;Container&quot; 
              driverClassName=&quot;com.mysql.jdbc.Driver&quot; 
              maxIdle=&quot;30&quot; maxTotal=&quot;100&quot; 
              maxWaitMillis=&quot;10000&quot; 
              name=&quot;jdbc/heroku_a6ba2d62a41cee6&quot; 
              password=&quot;...&quot; 
              type=&quot;javax.sql.DataSource&quot;
              url=&quot;jdbc:mysql://us-cdbr-east-04.cleardb.com/heroku_a6ba2d62a41cee6?reconnect=true&quot;
              username=&quot;...&quot;/&gt;
  &lt;/Context&gt;`
  </code></pre>
  <p>I am using a listener for sessions and suppose the problem is there:</p>
  <pre><code>`@Override
      public void contextInitialized(ServletContextEvent sce) {
          try {
              Context initContext = new InitialContext();
              Context envContext = (Context) initContext.lookup(&quot;java:/comp/env&quot;);
              DataSource ds = (DataSource) envContext.lookup(&quot;jdbc/heroku_a6ba2d62a41cee6&quot;);`
  </code></pre>