Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading properties file problem

 
Angus Rose
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I'm up against one of those irritating classpath problems. Let me explain the scenario:

I have an application deployed as a jar file. This application reads a properties file when it fires up. This properties file needs to be placed in a different directory when deployed so that the administrator can edit the properties contained within it. I have tried several ways of reading this file including
InputStream l_isAttillaPropertiesInputStream = this.getClass().getClassLoader().getResourceAsStream("AttillaQ.properties");

Currently, the properties file sits in the same directory as the jar file containing the application and the directory is on the classpath. Alas, the InputStream object is still null, i.e. the classloader cannot find the properties file.

Please help me!!!

Angus
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving....
 
Angus Rose
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for moving it. Any chance of some help now please?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your classpath.

How are you running the application? As an executable JAR (with "java -jar myprogram.jar")? If you're doing that, then Java will ignore the CLASSPATH environment variable or any "-classpath" or "-cp" switches on the command line. For executable JARs, you specify the classpath in the manifest file of the JAR.
 
Angus Rose
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for the reply. My manifest looks like this:

Manifest-Version: 1.0
Created-By: Oracle JDeveloper 10g 10.1.3.0.4
Main-Class: uk.ac.ukbiobank.attillaq.AttillaQJobScheduler
Class-Path: . \resources\AttillaQ.properties

and the directory structure is as such:

-AttillaQ
|
-AttillaQ.jar
|
--resources
|
-AttillaQ.properties

Currently it's deployed to Windows OS.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your manifest file end with a blank line? (Read this).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic