6 Replies Latest reply: Feb 14, 2010 8:54 PM by 843810 RSS

    How to run applications that use resource bundle - jvm not able to find res

    843810
      Hi,

      I am puzzled over how to run applications that use resource bundle - jvm is not able to find resources referenced in the program. Getting following exception:
      Exception in thread "AWT-EventQueue-0" java.util.MissingResourceException: Can't find bundle for base name ScreenTexts, locale en_US
              at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
              at java.util.ResourceBundle.getBundleImpl(Unknown Source)
              at java.util.ResourceBundle.getBundle(Unknown Source)
      My working directory is D:\RES_TEST>.
      The resource files are in a subfolder "Properties"

      I tried with (1) setting library path variable and (2) giving the classpth.

      D:\RES_TEST> java -Djava.library.path=Properties -jar <my_executable_jarred_app>

      Please help.

      Thanks,
      Joby

      Both ways it did not work.
        • 1. Re: How to run applications that use resource bundle - jvm not able to find res
          DrClap
          The library path has nothing to do with it. Resource bundles are loaded from the classpath. If that didn't work then your classpath is wrong, or the resource bundle is in the wrong place.
          • 2. Re: How to run applications that use resource bundle - jvm not able to find res
            843810
            Hi Paul,

            Thanks for the response. Could you please tell me how will specify my properties file in the following location to the jVM as classpath?

            D:\RES_TEST\Properties\Messages_en_US.properties

            my app will be running from D:\RES_TEST.

            will this be correct. Bu this did not work..

            D:\RES_TEST> java -cp Properties -jar <executable-jar>

            Thanks,
            Joby
            • 3. Re: How to run applications that use resource bundle - jvm not able to find res
              DrClap
              You're using the -jar option to run your jar as an executable jar? Then the -cp option does nothing. The classpath comes from the manifest in your jar file.

              But in real life I would put the resource bundle in the jar file with the classes. Trying to distribute it separately and set up an entry in the manifest to include it in the jar's classpath would be way to much trouble.
              • 4. Re: How to run applications that use resource bundle - jvm not able to find res
                843810
                Thanks Paul once again, My intention was to make the properties file as a seperate one so that the use may change properties / messages without rebuilding the project. Anyways, if no other option is available, i have to stick to this....

                Regards
                Joby
                • 5. Re: How to run applications that use resource bundle - jvm not able to find res
                  DrClap
                  JOBY1985 wrote:
                  Thanks Paul once again, My intention was to make the properties file as a seperate one so that the use may change properties / messages without rebuilding the project. Anyways, if no other option is available, i have to stick to this....
                  There are plenty of options. However all of them involve some design up front, which you haven't done yet. In my opinion the best option is this:

                  You distribute the default version of the properties file in the jar file. Your code uses that version if nothing else is available. (You access that version via the classpath.)

                  If the user wants to customize the properties, then you save the modified version in the user's directory. Your code looks for that version first, and if it's not there then it uses the default version from the jar file. (That version is in a known location, so you access it from there.)

                  I don't understand what you mean by "rebuilding the project" there. This "project" is something in your development environment, isn't it? Surely you aren't expecting the user to install Netbeans or something like that just to run your application?
                  • 6. Re: How to run applications that use resource bundle - jvm not able to find res
                    843810
                    Thanks Paul. Finally I did it, using the normal procedure. I dont have a runnable jar now.. i give my jar file in the classpath + the properties file path. and then i give the class to run,

                    java -cp myjar.jar;PropertiesfilePath <MainClass>

                    Now it works fine,.

                    Thanks for your advice and time

                    Regards
                    Joby