I have a Java webapp WAR file that depends on several jars in this WEB-INF \ lib directory. One of these JARS needs to load some configuration files by running class.getClassLoader().getResourceAsStream(...) . However, an InputStream returns zero. Is there a problem with this approach when the JAR is inside the WAR? The application is deployed on Tomcat6.
EDIT MORE INFO:
I am trying to load SQL queries from files so that I can run them. They are located in a separate DAO bank in the WAR web application, in the WEB-INF / lib section
mywebapp.war
EXTERNAL CLASS USE CODE
public class QueryLoader { private static final Logger LOGGER = Logger.getLogger(QueryLoader.class.getName()); public String loadQuery(String fileName) { final String newline = "\n"; BufferedReader reader = new BufferedReader(new InputStreamReader( QueryLoader.class.getClassLoader().getResourceAsStream( "/com/companyname/queries/" + fileName))); StringBuilder sb = new StringBuilder(); String line; try { while ((line = reader.readLine()) != null) { sb.append(line); sb.append(newline); } } catch (IOException e) { LOGGER.error(e); }
I also tried changing the getResourceAsStream line to
Thread.currentThread().getContextClassLoader().getResourceAsStream(
without success.
My development environment is MS Windows Vista, but I encounter the same error when I run it in this environment and on Ubuntu.
java tomcat deployment
Tarski
source share