Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3455470
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:37:07+00:00 2026-05-18T09:37:07+00:00

I have a Java webapp WAR file that depends on multiple jars in it’s

  • 0

I have a Java webapp WAR file that depends on multiple jars in it’s WEB-INF\lib directory. One of these JARS needs to load some config files by doing class.getClassLoader().getResourceAsStream(...). However the InputStream resturns null. Is there a problem with taking this approach when the JAR is inside a WAR? The app is deployed on Tomcat6.

EDIT MORE INFO:

I’m tring to load in SQL queries from files so I can run them. These are located in a separate DAO jar within the web app’s WAR, under WEB-INF/lib

mywebapp.war
        -- WEB-INF
          -- lib
             -- mydao.jar
               ---- com/companyname/queries
                   -- query1.sql
                   -- query2.sql
                   -- query3.sql
                   ...

CODE USING TO LOAD CLASSES

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 have also tried changing the getResourceAsStream line to

Thread.currentThread().getContextClassLoader().getResourceAsStream(

without success.

My development environment is MS Windows Vista and but I encounter the same error when running it on this environment and on Ubuntu.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:37:07+00:00Added an answer on May 18, 2026 at 9:37 am

    Managed to get it to work by using Spring’s resource loader instead

    public String loadQuery(String fileName) {
      final String newline = "\n";
    
      ApplicationContext ctx = new ClassPathXmlApplicationContext();
      Resource res = ctx.getResource("classpath:/com/msi/queries/" + fileName);
      BufferedReader reader;
      StringBuilder sb = new StringBuilder();
      try {
         reader = new BufferedReader(new InputStreamReader(res.getInputStream()));
         String line;
    
         while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append(newline);
         }
      } catch (IOException e) {
         LOGGER.error(e);
      }
    
      return sb.toString();
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java-webapp. The webapp is packaged as a war-file. These war-file allow
I have a java webapp that has to be deployed on either Win or
Situation is pretty straightforward. I have a Java webapp that I'm converting to be
I'm trying to make an executable war file ( java -jar myWarFile.war ) that
I have a new web app that is packaged as a WAR as part
I have a Java web application that uses the SLF4J logging facade. To date,
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
Does Java have a built-in way to escape arbitrary text so that it can
Does Java have a data type that represents a period of time eg 34

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.