8 Replies Latest reply: Jul 12, 2010 5:56 AM by 843804 RSS

    Not able to locate the .properties file in JAR in a referenced application

    843804
      Hi,

      I have created a JAR file which contains the .class as well as .properties in my application. Similarly when generating the JAR i have included the respective JAR's as well as the Main class of the app. in the Manifest.MF file.
      Below is the code i am using to load the properties from the LoggerConstants.

      if (properties == null) {
      try {
      properties = new Properties();
      properties.load(Thread.currentThread().getContextClassLoader()
      .getResourceAsStream (LoggerConstants.LOGGER_PROPERTIES_PATH));
      PropertyConfigurator.configure(properties);
      } catch (IOException ioe) {
      throw new LoggerException("unable to load file="
      + LOGGER_PROPERTIES_PATH, ioe);
      }
      }
      When i access the JAR in other app. by putting that in the build path, i am getting the following exception:-

      Exception in thread "main" java.lang.NullPointerException
      at java.util.Properties$LineReader.readLine(Properties.java:418)

      It seems that it is not able to pick the .properties which is there in the JAR file? But it is able identify the .class file?
      I tried by copying the same in the ANT Class path in eclipse, but still the problem persists. What i need to make sure that the .properties will be identified by the other app (App. 2)?

      the logger.properties will be under the classpath in the eclipse which will be under " src/com/example/logger.properties" directory. To brief , i am going to give this logger app. by compressing it in the JAR and will send to another machine , they need to use this JAR in their application and make use of the LogLevels i have created. The same will be done for other app. as well. So a Single Logger comp. which is build independently will be used by other standalone app. which needs to log the information.

      1) So, when i give the "LoggerComponent" JAR to other application. they should not modify any code (or create any classes) to use the .class or the .properties of the JAR?
      2) .class may not be a problem, but with .properties which may be a problem, hence are you saying that we need to load the logger.properties again in the referenced app. explictly, like wise do it for other app. which is going to use it? Because from my side i will give the Logger Comp. JAR to the other machines, just they need to use it as it is, without any modification in their code.
      3) Moreover when i create a JAR whether i need to package log4j.jar as well as other dependent JAR for the logger app.? So that the other reference app. dont have their own log4j.jar in their system to make use of it? Whether that makes sense or we should package a JAR with other JAR's(dependent JAR of the app.)?
      4) Ok. say if i am going to access the properties in my JAR in the reference app., like:-

      String sConfigFile = "src/com/example/logger.properties";

      InputStream in = LoggerTest.class.getClassLoader().getResourceAsStream(sConfigFile);
      if (in == null) {
      //File not found! (Manage the problem)
      }
      Properties props = new java.util.Properties();
      props.load(in);

      LogManager logManager = new LogManager(); // Main class in the LoggerApplication JAR used in the reference app.
      logManager.logMessage("Test log msg");

      I will load properties and invoke the main class in JAR like above? Please clarify these queries. Thanks for the support


      Thanks,
      Rithu