Search code examples
luceneopencmsweb-inf

How to acces a file under WEB-INF from a Java web application


Do you have any idea how to access files in WEB-INF/index folder from my application? I'm using OpenCMS for my application and I want to open a Lucene search index (with the help of Lucene IndexReader class) located at WEB-INF/index folder. Lucene jar is stored in WEB-INF/lib folder.


Solution

  • If you want to lookup a file on the RFS (real file system) under the WEB-INF folder, you can get the path via:

    String filepath = pageContext.getServletContext().getRealPath("/") + "WEB-INF" + java.io.File.separator + "index";
    

    and then use the common java file methods to read it.