title: Tomcat cant read file that is read locally
body: <p>I have this code in my <code>CacheInitializer</code> which implements <code>ServletContextListener</code></p>
  
  <pre><code>ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          File file = new File(classLoader.getResource("synonyms.txt").getFile());
          if (file != null &amp;&amp; file.exists()) {
              try (Scanner scanner = new Scanner(file)) {
                  while (scanner.hasNextLine()) {
                      String line = scanner.nextLine();
                      String leftHand = line.split("=&gt;")[0];
                      String rightHand = line.split("=&gt;")[1];
  
                      for (String s : leftHand.split(",")) {
                          if (s.equals(""))
                              continue;
                          synonymsLookupMap.put(s.trim(), rightHand.trim());
                      }
                  }
                  scanner.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          } else {
              throw new RuntimeException("Synonyms file not found");
          }
  </code></pre>
  
  <p><code>sysnonyms.txt</code> file resides inside resources folder. When I try to run this code locally (Mac OSX), it runs perfectly fine. But when I deploy the same war on my Amazon Linux EC2 machine, no contents are read. I tried remote debug and code never enters the while loop. No exception is thrown either. It finds the file but behaves as if its empty, and there are no lines to be read. I tried creating synonyms.txt through vi on server and then using that to see if it was a file format issue. It did not work either.</p>
  
  <p>Any idea what must be the issue?</p>