0

I am migrating a project to a servlet. I put the jars in the lib directory, the compiled classes in classes directory. However, I have some files (properties, a wsdl file) that I am loading and reading in my application. For example this is how I am loading my properties:

try {
    InputStream in = new BufferedInputStream(new FileInputStream("my.prop"));
    myConfig.load(in);
} catch (Exception e) {
    logger.error(e.getMessage(), e);
}

Where do those files that I am loading go?

oneiros
  • 3,527
  • 12
  • 44
  • 71

1 Answers1

1

They usually go straight in the classpath so that you aren't dependent on the current working directory of the local disk file system. But you've got to change the way how you're getting an inputstream:

InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("my.prop");

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • So, that is how you add it to the classpath? If I want to add jars to the classpath will placing them in the lib directory do the deal? Or do I have to add them in this fashion? – oneiros Dec 20 '11 at 20:12
  • Just either drop in `src` folder of your project, there where you have your packages (the IDE will take care that it ends in `/WEB-INF/classes` which is part of the classpath), or put it somewhere on a fixed path in disk file system and add that path to the classpath in server configuration. See also the 1st "See also" link. – BalusC Dec 20 '11 at 20:14
  • BalusC thank you very much for your answers. You have helped me a great deal. I really appreciate you taking the time to answer. Keep up the great work. – oneiros Dec 21 '11 at 07:02