2

In order to internationalise my code, I use a property file called MessagesBundle_en_UK.properties which is located in a resource folder called config so that I the following structure:

+---src
      \---com
            \---proj
                   \---messages
                              Messages.java  
+---config
         \---languages
                    MessagesBundle_en_UK.properties

Messages.java has:

    currentLocale = new Locale("en", "UK");
    messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);

and I have added config/languages at the beginning of the classpath and it works fine when I run the program with javac/java from the command line.


My problem is that it doesn't work when I run the jar and I get this MissingResourceException error.

although the manifest does include config/languages:

    Class-Path: 
      ./config/languages 
      ./libs/xxxx.jar
      ./libs/...
      ...

I'm bit confused...

Thanks for the help David

2 Answers 2

3

You should reference the location of your ResourceBundle relative to the root as if it were a member of a package:

messages = ResourceBundle.getBundle("config.lagnuages.MessagesBundle",currentLocale);
Sign up to request clarification or add additional context in comments.

Comments

0

I think the issue here is that you're trying to add a directory to the manifest Class-Path and but don't end it with a / character. From the Extension Mechanism documentation:

An application (or, more generally, JAR file) specifies the relative URLs of the optional packages (and libraries) that it needs via the manifest attribute Class-Path. This attribute lists the URLs to search for implementations of optional packages (or other libraries) if they cannot be found as optional packages installed on the host Java virtual machine*. These relative URLs may include JAR files and directories for any libraries or resources needed by the application or optional package. Relative URLs not ending with '/' are assumed to refer to JAR files. For example,

Class-Path: servlet.jar infobus.jar acme/beans.jar images/

Most people bundle their properties files in their jars. For example:

+---jar_root
      \---com
            \---proj
                   \---messages
                              Messages.class
                              MessagesBundle_en_UK.properties

This bundle would have the name "com.proj.messages.MessageBundle".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.