title: Reading Web Application Resources
body: <h2>Background</h2>
  
  <p>Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate XML files.</p>
  
  <h2>Problem</h2>
  
  <p>The "Business Area" list queries against the database, and the "Column Cluster" list queries the database using the selected "Business Area" items. Both of these are unique queries that are stored external text files.</p>
  
  <p>The files are currently stored in the following locations:</p>
  
  <ul>
  <li>WebContent/META-INF/business-areas.sql</li>
  <li>WebContent/META-INF/column-clusters.sql</li>
  </ul>
  
  <p>These are then used to seed <code>PreparedStatement</code>s.</p>
  
  <h2>Source Code</h2>
  
  <p>The method to read the SQL code might resemble:</p>
  
  <pre><code>  private String getSQL() {
      String result = "";
  
      try {
        BufferedReader br = open( "business-areas.sql" );
        String line = null;
  
        while( (line = br.readLine()) != null ) {
          result += line;
        }
  
        br.close();
      }
      catch( Exception e ) {
        e.printStackTrace();
      }
  
      return result;
    }
  </code></pre>
  
  <h2>Questions</h2>
  
  <p>I would like to know:</p>
  
  <ol>
  <li>What are the best practices for storing such assets for deployment as part of a web app? (That is, is <code>META-INF</code> a good location, or is <code>META-INF/resources</code> preferred?)</li>
  <li>What APIs would you recommend for reading the file content? (That is, how do I write the <code>open</code> method so that it finds the files to open?)</li>
  </ol>
  
  <p>I already have JNDI in place to establish the database connection, but would rather not use JNDI to obtain handles to the files, if possible.</p>
  
  <h2>Related Sites</h2>
  
  <ul>
  <li><a href="http://blogs.oracle.com/alexismp/entry/web_inf_lib_jar_meta" rel="noreferrer">http://blogs.oracle.com/alexismp/entry/web_inf_lib_jar_meta</a></li>
  <li><a href="http://www.avajava.com/tutorials/lessons/where-do-i-put-resources-in-my-maven-project.html" rel="noreferrer">http://www.avajava.com/tutorials/lessons/where-do-i-put-resources-in-my-maven-project.html</a></li>
  <li><a href="http://docs.jboss.org/jbossweb/3.0.x/config/context.html" rel="noreferrer">http://docs.jboss.org/jbossweb/3.0.x/config/context.html</a></li>
  <li><a href="http://tomcat.apache.org/tomcat-4.0-doc/catalina/docs/api/org/apache/naming/resources/FileDirContext.html" rel="noreferrer">http://tomcat.apache.org/tomcat-4.0-doc/catalina/docs/api/org/apache/naming/resources/FileDirContext.html</a></li>
  </ul>
  
  <p>Thank you!</p>