ResourceBundle outside jar

I'm packing my application in a jar file which looks like this
*/MainApp.class*
*/Language_de.properties*
*/Language.properties*
Both properties files are for I18N purpose.
In the code I load ResourceBundle like this
ResourceBundle.getBundle("Language");And it works fine.
But if I drop a new language file Language_fr.properties
and change Region to France.
The ResourceBundle cannot fine this new properties file and
fallback to Language.properties inside .jar
What can I do to fix this ?

Try this method for a particular locale.
getBundle(String baseName,Locale locale)For instance, if you are using "France",
getBundle("Language",Locale.FRANCE).I think, Since you are using ResourceBundle.getBundle("Language");, it gives you default one. See this link for more details
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String)
Edited by: SekarOnWeb on Dec 5, 2007 10:37 AM

Similar Messages

  • Can't get ResourceBundle from jar.

    Dear all,
    I have problem in geting properties from file included in jar file. I try to do it by calling mthod ResourceBundle.getBundle("bundle"), where bundle.properies is the file in jar. When I run the programm by calling :
    java -jar dist/properties.jar
    I have the following rsult on the console:
    Exception in thread "main" java.util.MissingResourceException: Can't find bundle
    for base name bundle, locale pl_PL
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:712)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:683)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:546)
    In case I run this program, using not jar'ed classes everything is ok.
    P.S. the manifest file of the jar is:
    Manifest-Version: 1.0
    Created-By: Apache Ant 1.5.1
    Main-Class: PropertiesLoader
    Thanks in advance for all answers.
    Daniel Kwiecińśki

    According to ResourceBundleAPI:
    Calling this method is equivalent to calling
        getBundle(baseName, locale, this.getClass().getClassLoader()),
    except that getClassLoader() is run with the security privileges of ResourceBundleTry this code, it will obtain the application's ClassLoader and will enable the location of the properties file in all the classpath defined for it.
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            resources = ResourceBundle.getBundle(BUNDLE_BASENAME, locale, loader);Good Luck!

  • Problem with ResourceBundle in Jar

    Hi,
    I've written the following class which works perfectly in my program but not when used in the same code but distributed as a Jar file.
    In this case, only the default locale is used on a "Messages.getString" call, even if I swith the local to English...
    I've read that there was a "bug" in the j2sdk1.4.2_05 and I'm using the j2sdk1.4.2_06.
    Do you have any idea ?
    Thanks,
    Marc.
    package com.oxiane.marketing.IHM;
    import java.util.Locale;
    import java.util.MissingResourceException;
    import java.util.ResourceBundle;
    * Classe servant � g�rer les langues Anglaise et Fran�aise pour
    * l'interface.
    public class Messages {
         private static final String BUNDLE_NAME = "Messages" ;
         private static ResourceBundle RES_BUNDLE_FR = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
         private static ResourceBundle RES_BUNDLE_EN = ResourceBundle.getBundle(BUNDLE_NAME, Locale.ENGLISH);
            public static String getString(String msg){
                 try {
                      if (Locale.getDefault().getLanguage() == "fr")
                           return RES_BUNDLE_FR.getString(msg);
                      else
                           return RES_BUNDLE_EN.getString(msg);
                 catch (MissingResourceException e){
                      System.out.println(e.getMessage());
                      return "";
         public static void setLocale(Locale loc){
              Locale.setDefault(loc);
         public static Locale getLocale(){
              return Locale.getDefault();
    }

    You should take care of the directory structure according to the package structure.
    I for example have this jar:
    C:\source\java\ebank2_util\smsunlock>unzip -l pro-ebank_sms_unlock.jar
    Archive:  pro-ebank_sms_unlock.jar
    Length    Date    Time    Name
          0  10-28-05  17:27   hu/
          0  10-28-05  17:27   hu/khb/
          0  10-28-05  18:17   hu/khb/smsunlock/
        256  11-07-05  16:33   hu/khb/smsunlock/DButils$MySQLException.class
       4229  11-07-05  16:33   hu/khb/smsunlock/DButils.class
       1700  11-07-05  16:33   hu/khb/smsunlock/GUI$1.class
       2318  11-07-05  16:33   hu/khb/smsunlock/GUI$2.class
        988  11-07-05  16:33   hu/khb/smsunlock/GUI$3.class
       1402  11-07-05  16:33   hu/khb/smsunlock/GUI$mywl.class
       5630  11-07-05  16:33   hu/khb/smsunlock/GUI.class
        818  11-07-05  16:33   hu/khb/smsunlock/LimitedLength_TextField.class
       2452  11-07-05  16:33   hu/khb/smsunlock/Main.class
        900  11-07-05  16:33   hu/khb/smsunlock/MyInputStream.class
          0  11-07-05  16:33   META-INF/
         98  10-27-05  15:53   META-INF/manifest.mf
         90  11-07-05  16:33   hu/khb/smsunlock/properties
      20881                    16 filesAnd the resource is loaded like this from hu.khb.smsu.Main:
    InputStream is = new MyInputStream( Main.class.getResourceAsStream( "properties" ) );

  • ResourceBundles in jars, applet, connection refused

    Hi,
    we run our code as application and as applet.
    We have a lot of ResourceBundle files (ListResourceBundles) which are archived per language (RBjars).
    The application and applet is in another package than the RBjars.
    An URLClassloader for loading the ResourceBundles is used which contains only the necessary language resource bundle jar file ( ResourceBundle.getBundle(resBundleName, locale, rbClassloader) ).
    When running as applet we get an exception (java.net.ConnectException: Connection refused: connect), although correct RBJar is loaded from server.
    When running as application we get same exception (java.net.ConnectException: Connection refused: connect),
    index and manifest used when archiving main package, but RBJars not in classpath of manifest, nor there are in the archive attribute of html of applet.
    If we define all RBjars in classpath of manifest (or in archive attribute), the applet allways load all RBjars, that cost too much time. This is the main problem.
    If anyone has an idea how to handle a lot of resource bundle jar files in an applet, please let me know.
    Thanks,
    Inge

    While one cannot say for sure, it looks like your problem is only tangentially connected with Java, jars, or applets. "Connection refused" means that there wasn't an HTTP server running at the address you gave to supply whatever file you asked for.
    It's probably a configuration or administration problem. Try typing the URL the program is using into your web-browser and see if you get the file.

  • Access of MySQlL Driver class by eclipse but not from Outside Jar file

    Dear All,
    I have done a standalone application having access with MySQl database.
    I could access it when i execute it from eclipse. But when i export it into Jar file and running I get MySQL Driver class not found exception.
    Give me a better solution for this issue.

    CLASSPATH, CLASSPATH, CLASSPATH.
    You have defined the Eclipses Project Library Path to include the MySQL jar, but ar not including it on the classpath when executing the jar.
    Either modify the MANIFEST.mf file in the jar to include a reference to the MySQL driver jarfile or call java in the following manner
    java -cp /full/path/to/MySQL/Driver/jarfile.jar -jar yourJarFile.jarObviously, if this is on Windows and you are executing through a double click, the first option is the best option.

  • Classloader won't let me delete jar file!

    Hi-
    I am writing a classloader that runs main from a class called MyMain. MyMain loads classes from a jar file called MattTable.jar. I need to be able to delete the jar file once the classes are loaded from it, or even just delete it at the end of the program. Either way, the classloader will not release it so I cannot delete the jar file until after my program finishes. I want to be able to delete it from with in my code after the method is invoked.
    URL urls[] = new URL[] { new File(".").toURL() };
    URLClassLoader loader = new URLClassLoader( urls );
    Class c = loader.loadClass(mainClass);
    Method m1 = c.getMethod("main", new Class[] { args.getClass() });
    //main loads classes from an outside jar file
    m1.invoke( null, new Object[] {args} );
    //Here is where I want to delete the jar file
    //I would even accept file.deleteOnExit() but this won't work either
    If anyone can help me figure out how to delete this file, it would be a great help!
    Thanks,
    Matt

    Hi,
    I've created a small classloader for jar files which releases the handle every time a class is loaded. It might still need some optimization, but at least it works:import java.util.zip.*;
    import java.util.*;
    import java.io.*;
    public class ZipClassLoader extends ClassLoader {
         private Hashtable classes = new Hashtable();
         private File f;
         public ZipClassLoader(String zipFileName) {
              this (new File(zipFileName));
         public ZipClassLoader(File zipFile) {
              f = zipFile;
         public Class loadClass(String className) throws ClassNotFoundException {
              return (loadClass(className, true));
         public synchronized Class loadClass(String className, boolean resolve) throws ClassNotFoundException {
              if (classes.containsKey(className)) return (Class)classes.get(className);
              ZipFile zipFile = null;
              BufferedInputStream bis = null;
              byte[] res = null;
              try {
                   zipFile = new ZipFile(f);
                   ZipEntry zipEntry = zipFile.getEntry(className.replace('.', '/')+".class");
                   res = new byte[(int)zipEntry.getSize()];
                   bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
                   bis.read(res, 0, res.length);
              } catch (Exception ex) {
              } finally {
                   if (bis!=null) {
                        try {
                             bis.close();
                        } catch (IOException ioex) {}
                   if (zipFile!=null) {
                        try {
                             zipFile.close();
                        } catch (IOException ioex) {}
              if (res == null) return super.findSystemClass(className);
              Class clazz = defineClass(className, res, 0, res.length);
              if (clazz == null) throw new ClassFormatError();
              if (resolve) resolveClass(clazz);
              classes.put(className, clazz);
              return(clazz);
    }This is the test program I've created. It loads a class from the Apache log4j jar file, and deletes the file when the class is loaded:import java.io.File;
    public class Test {
         public static void main(String[] args) throws Exception {
              File f = new File("C:\\jartest\\log4j-1.2.6.jar");
              ZipClassLoader zl = new ZipClassLoader (f);
              Class c = zl.loadClass ("org.apache.log4j.ConsoleAppender", true);
              Object o = c.newInstance();
              System.out.println (o.getClass().getName());
              f.delete();
    }

  • This JAR is driving me crazy! Dukes to come...

    Hi all,
    I can create an executable jar, both programmatically and from the command line and the internal directory structure comes out fine, just as expected. However, If I double click on it, I get the dreaded "Cannot find main class, program will exit" error.
    I have checked and double checked my manifest and it seems fine too. This is what is created inside the jar:
    Directory called "jai" containing class files
    Directory called "META-INF" containing one file, "manifest.mf"
    Manifest looks like this:
    Manifest-Version: 1.0
    Main-Class: jai.Run
    including the empty line at the end. Run.class does exist inside jai. I have also tried changing the main class to jai/Run with the same result. I just have no more ideas on what could be wrong even after trawling through the many postings on this topic. Any suggestions would be reaaaallly appreciated. I am so desperate that I will definitely add Dukes to this topic when I next get some more, but at the moment I'm all out!
    Thanks in advance!

    buckman1:
    you may be on to something. There IS a jar inside the jar. The purpose of the main class is to extract the files from the outside jar, and run this one. (Frustratingly, the jar inside executes perfectly when double clicked!). Can you expand on what I have to do in the manifes? However, I don't think that's my problem as the error message is "Can't find main class", so it leads me to believe that the main class doesn't even get a chance to run.
    Here's the directory structure inside the jar:
    /META-INF/MANIFEST.MF (on checking, this always gets changed to upper case even if you add it in lower case).
    /jai/Run.class
    /jai/ua.jar
    /jai/data/installConfig.txt
    and that's it - only small.
    Below is the Run code (obviously untested as I can't get the jar to run!):
    package jai;
    import java.lang.Runtime;
    import java.io.*;
    import java.net.URL;
    import java.util.*;
    import java.util.jar.*;
    import java.util.zip.*;
    import java.security.*;
    public class Run {
      public Run() {
      public static void main(String[] args) throws IOException {
        extract();
      private static URL getJar() {
        Class theClass = new Run().getClass();
        ProtectionDomain pDomain = theClass.getProtectionDomain();
        CodeSource codeSource = pDomain.getCodeSource();
        URL loc = null;
        try {
          loc = codeSource.getLocation();
        catch (Exception ex) {
          ex.printStackTrace();
        return loc;
      private static void extract() throws IOException {
        String strJarFileName = getJar().toString();
        JarFile theJar = new JarFile(strJarFileName);
        Enumeration enuJarEntries = theJar.entries();
        while (enuJarEntries.hasMoreElements()) {
          JarEntry jeFile = (JarEntry) enuJarEntries.nextElement();
          //strTempDir is the Dir where the files are to be unjarred
          File oneFile = new File(System.getProperty("java.io.tmpdir") + "/" +
                                  "JAITEMP" + "/" + jeFile.toString());
          if (jeFile.isDirectory()) {
            oneFile.mkdir();
          else {
            CheckedInputStream cis = new CheckedInputStream
                (theJar.getInputStream(jeFile), new CRC32());
            FileWriter fw = new FileWriter(oneFile);
            BufferedWriter bw = new BufferedWriter(fw);
            for (int i = 0; i < jeFile.getSize(); i++) {
              bw.write(cis.read());
            bw.flush();
            bw.close();
            fw.close();
    }

  • Extract nested Jar File

    Okay, I've been looking all day for solutions to this problem and nothing I've found pinpointed the solution, so if anyone would rather point me to another site, that's great.
    I have a .jar installer ( installer.jar ) that contains the installer code and a nested jar file ( program.jar ).
    In my experience, plain text files work great in the "getInputStream() -> FileWriter.write()" method, but my way of handling images requires javax.imageio.ImageIO, and i'm hoping something similar exists for jars.
    ALL+* i want to do is extract that jar file into the current directory, but the ZipEntry.getInputStream() method didn't work, and JarInputStream just confuses me.
    If anyone has links to other topics or source code to point to how a jarfile can be extracted.

    Thanks for the help.
    After looking around and finally noticing the Pack200 package, I have the answer!
    JarFile jf = new JarFile( "outside.jar" );
    JarOutputStream jos = new JarOutputStream( new FileOutputStream( new File( "inside.jar" ) ) );
    Pack200.newUnpacker().unpack( jar.getInputStream( jar.getEntry( "inside.jar" ) ), jos );
    jos.close();This creates a JarOutputStream that will write to the FileOutputStream forever until closed.
    The Pack200 Unpacker takes the inputstream and outputs it to the JarOutputStream.
    When the unpack method returns, the jar file is ready. Close the jar output stream and you have a workable jar!

  • How to increase heap size in java code, not using "java -Xms64m "

    Im writing a java programme for loading the german dictionary. my dictionary is very huge(around 300000+ words).
    while loading the dictioanry im getting error "OutOfMemoryError" .
    I found one solution to increase the heap size, but i want to increase the heap size in java programmer itself, not outside jar file. so i could not use "-Xms64m" option of jvm.
    Can anyone tell me how can i do this

    sunlover1984 wrote:
    Im writing a java programme for loading the german dictionary. my dictionary is very huge(around 300000+ words).
    while loading the dictioanry im getting error "OutOfMemoryError" .
    I found one solution to increase the heap size, but i want to increase the heap size in java programmer itself, not outside jar file. so i could not use "-Xms64m" option of jvm.
    Can anyone tell me how can i do thisThat option is a startup option for the JVM. That means if your jar is already loaded then you are already too late to try and call it.

  • Still NoClassDefFoundError

    Hi,
         I am still getting the NoClassDefFoundError, I am testing with the following code.
    //file:OracleTest.java
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import oracle.jdbc.OracleDriver;
    public class OracleTest {
    public OracleTest() {
    try {
    System.out.println("Before Load...");
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    System.out.println("After Load...");
    catch (SQLException SQLe) {
    System.out.println("SQL Error: "+ SQLe);
    catch (NoClassDefFoundError e) {
    System.out.println("Error: "+ e);
    public static void main (String[] args) {
    OracleTest ot = new OracleTest();
         This gives the following results.
         Outside Jar:
    Before Load...
    After Load...
         Inside Jar:
    Before Load...
    Error: java.lang.NoClassDefFoundError: oracle/jdbc/OracleDriver
         I have the following classpath set.
    set classpath=.;c:\jdk2\;c:\jdk2\classes12.zip
         Any help would be appreciated.
    Best Regards,
    Mick.

    Almost all class not founds relate to the classpath. This is a class which you can use to determing exactly what class the classloader has visibility on. This will rule out any duplicate classes on your classpath. It depends on the order in which you set your classpath. You could also check that when you set the environment, that you are not setting it locally using set local and running the app in a web server or something. Here you cannot establish the run time classpath.
    I hope this helps you.
    Try running the following code:
    public class JWhich
    * Prints the absolute pathname of the class file
    * containing the specified class name, as prescribed
    * by the current classpath.
    * @param className Name of the class.
         public static void which(String className)
              if (!className.startsWith("/"))
         className = "/" + className;
              className = className.replace('.', '/');
              className = className + ".class";
              java.net.URL classUrl = new JWhich().getClass().getResource(className);
              if (classUrl != null)
                   System.out.println("\nClass '" + className + "' found in \n'" + classUrl.getFile() + "'");
              else
                   System.out.println("\nClass '" + className + "' not found in \n'" +
                   System.getProperty("java.class.path") + "'");
         public static void main(String args[])
              if (args.length > 0)
                   JWhich.which(args[0]);
         else
         System.err.println("Usage: java JWhich <classname>");

  • WebOS Doctor encounters error updating touchpad/t​ouchpanel firmware

    I have encountered an issue with my TouchPad in that the panel no longer responds to touch.  It may have something to do with preware, but I should think that the webOS doctor would reset everything on the unit so that i could start over.  All attempts to run webOS Doctor encounter a firmware error leaving the unit unusable.
    Here's the version of webOS doctor as best i can tell:
    Sep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: com.palm.nova.installer.recoverytool.MainFlasher is loaded from: http://palm.cdnetworks.net/rom/touchpad/p302r0d080​12011/wifip302rod/webosdoctorp302hstnhwifi.jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: jarFile path is: \rom\touchpad\p302r0d08012011\wifip302rod\webosdoc​torp302hstnhwifi.jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: full path of the baseBuild file outside jar is: \rom\touchpad\p302r0d08012011\wifip302rod/webOS.ta​rSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: full path of the customizationBuild file outside jar is: \rom\touchpad\p302r0d08012011\wifip302rod/hp.tarSe​p 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: found resource in jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: Base build file found inside jar and loaded sucessfully
    And here is the error:
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Starting: Touch Panel Updater
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: Updating the touch panel firmware
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: 'hidd' is already in stopped state
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: i2c: error 110 during read/write
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: error reading present cy8ctma395 version, update must be forced to continue with 'PmTpUpdater -f'
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: Done updating the touch panel firmware
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Finished: Touch Panel Updater
    It goes downhill when it says 'hidd' is in stopped state and gets an error 110 from the panel.  It then appears to use a default firmware and when the doctor completes, the touch panel is unresponsive again.
    I should think that a firmware update would wipe everything clean, meaning it can't fail, if you will.  It's basically a reboot so why does it require anything from the unit (cy8ctma395 version)?
    Any ideas?  Thanx.
    Post relates to: HP TouchPad (WiFi)

    I have encountered an issue with my TouchPad in that the panel no longer responds to touch.  It may have something to do with preware, but I should think that the webOS doctor would reset everything on the unit so that i could start over.  All attempts to run webOS Doctor encounter a firmware error leaving the unit unusable.
    Here's the version of webOS doctor as best i can tell:
    Sep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: com.palm.nova.installer.recoverytool.MainFlasher is loaded from: http://palm.cdnetworks.net/rom/touchpad/p302r0d080​12011/wifip302rod/webosdoctorp302hstnhwifi.jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: jarFile path is: \rom\touchpad\p302r0d08012011\wifip302rod\webosdoc​torp302hstnhwifi.jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: full path of the baseBuild file outside jar is: \rom\touchpad\p302r0d08012011\wifip302rod/webOS.ta​rSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: full path of the customizationBuild file outside jar is: \rom\touchpad\p302r0d08012011\wifip302rod/hp.tarSe​p 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: found resource in jarSep 27, 2011 2:45:27 PM com.palm.nova.installer.recoverytool.MainFlasher configureFlasherThreadINFO: Base build file found inside jar and loaded sucessfully
    And here is the error:
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Starting: Touch Panel Updater
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: Updating the touch panel firmware
    Sep 27, 2011 2:53:39 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: 'hidd' is already in stopped state
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: i2c: error 110 during read/write
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: error reading present cy8ctma395 version, update must be forced to continue with 'PmTpUpdater -f'
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Touch Panel Updater: Done updating the touch panel firmware
    Sep 27, 2011 2:53:40 PM com.palm.nova.installer.recoverytool.CardControlle​r logPrintINFO: Finished: Touch Panel Updater
    It goes downhill when it says 'hidd' is in stopped state and gets an error 110 from the panel.  It then appears to use a default firmware and when the doctor completes, the touch panel is unresponsive again.
    I should think that a firmware update would wipe everything clean, meaning it can't fail, if you will.  It's basically a reboot so why does it require anything from the unit (cy8ctma395 version)?
    Any ideas?  Thanx.
    Post relates to: HP TouchPad (WiFi)

  • Refer ResourceBundle/external resources like icons from outside the Jar

    Hi,
    I have a swing application and I am using ResourceBundle to support internationalization. I also refer some icons.
    Now I have packaged my class file in a jar and I want to refer ResourceBundle and icons from outside the jar. This is to support runtime changing of values and icons without needing to recompile.
    When my code is in Eclipse and I try to refer the resource bundle, it is working fine. But as soon as I have a jar and try to refer the resource bundle from the class path, I am getting MissingResourceException.
    Please help.
    Regards,
    Manu

    As per my actual requirement, I wanted to have these properties files (resource bundles) and icons directly on the classpath, so that user has the convenience to modify them.
    I am not able to do so. I included the directory containing icons and resource bundle on the classpath, but i am not able to refer these icons from the main jar.So it works when the resources are in a 2nd jar, but not when they are in a folder that is in the classpath?
    Is the relative path of the resource files the same in both cases?
    In the simplest case (no nested folder), the icons are in the root of the jar, and the folder-equivalent is that they should be straight in the folder which you added in the classpath.
    Or are they (frequent case) in a nested folder, along your package structure, such as com/yourcompany/yourapp/gui/icon.jpg?
    In this latter case, you must not put folder "gui" in your classpath, but merely the folder which contains "com".
    I am just wild-guessing of course, for a more specific reply could you post a sketch of your jar/folder structure (in tags) and your command line, including
    the classpath part, in both the case that works and the one that doesn't?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Can ResourceBundle load .properties from files and .jar?

    Hi Guys,
    I'm trying to I18N an application with ResourceBundle.
    Suppose my class look like this:
    package pack;
    import java.util.ResourceBundle;
    public class MyClass {
        public static void main(String[] args) {
            ResourceBundle rb = ResourceBundle.getBundle("Language");
    }This would load the localized string from Language.properties
    And when I pack the class file and Language.properties into a jar. It works fine
    But what I tried to do is to make the ResourceBundle try to load from external file first
    before it load from the jar file so that if I have a new language file I can just drop in the
    NewLang.properties.
    Inside .jar file look like this
    /Language.properties
    /pack/MyClass.class
    /meta-inf/Manifest.mf
    I tried look into some forum and they suggest to include Class-Path in Manifest.mf file
    to include current path like this
    Class-Path: .
    But still, it didn't work. If I include .properties in .jar it will not look outside but if I didn't include
    any .properties it found a properties file.
    How can I achieve this ?

    Dave,
    I reckon you're on the right track... just have to figure out "what's the path to properties file"... I suspect you've got a context problem... not sure... I'm pretty new at this stuff myself.
    So, what's your development environment? O/S, IDE, app/web-server, etc.
    Cheers. Keith.

  • Reading Internationalised Bundles Outside of a Jar File

    I have seen this question many times throughout this forum and other forums where a jar file is tryingto load a resource outside of the jar file. The answers are often scattered or partial solutions. This is an attempt to provide a complete solution.
    Step 1)
    In your manifest file add to the Class-Path attribute the current directory, ie . plus any other library files you require (seperated with spaces).
    for example
    Class-Path: . lib/log4j.jar
    Step 2)
    In your code, make sure that you are correctly requesting the resource. If you are requesting a resource from the directory where you are running your jar file from (i.e. the working directory), simply use ResourceBundle.getBundle("Resource"); or equivalent method.
    If you bundle is within a directory, you must specify the directory when getting the Bundle as a dot seperated string, i.e.
    ResourceBundle.getBundle("etc.i18n.Resource"); would look for the file <working-directory)/etc/i18n/Resource.properties.
    I hope this may help people having problems with this excellent tool. Please feel free to add to this tutorial or amend any mistakes I may have made.
    Good Luck
    codemwnci

    I followed the instructions here and had every thing correct. I created the jar with ant using fearly standard build.xml. Things didn't still work out. Spent few hours wondering why things don't work.
    Reason: the property-files were not included in indexing.
    Basically there is two way around:
    1) Add the property files to the index of the jar.
    The problem here is that you cannot have new property-files without creating the index again.
    2) Don't do the indexing for the jar.
    In this case the jar is not so well optimazed, and in some case that may be a little problem.

  • My program cant find the locale-specific resourcebundle in the programs jar

    hi!
    i got a serious problem loading my resourcebundles from a jar file.
    it seems to be a often-talked-about problem in this forum but i didnt find an answer yet.
    please help me with this stuff:
    i made two resourcebundles for testing purposes in the following directory hierarchy:
    de/juw/jlogin/server/resources/....
    Text_de.properties
    Text_en.properties
    (no default properties wanted)
    this class shall load the resourcebundle (de.juw.jlogin.server.ServerTool):
    package de.juw.jlogin.server.ServerTool;
    public class ServerTool {
    private ResourceBundle rb;
    private Locale locale = Locale.getDefault();
    .... blah blah...
    public static ResourceBundle getResources() {
    if (rb == null) {
    rb = ResourceBundle.getBundle("resources/Text",locale);
    return rb;
    when i run that program (contained in a jar) it doesnt find the requested properties-file but works fine if all classes and the properties are outside of it.
    please help! i already spent two days on searching that forum and other sources without any results. i want that program (including the properties) in a jar-file.
    big thanks in advance

    I put my properties file and all other resources under in a resources directory in my jar e.g.:
    <package>/resources/App.properties
    <package>/resources/start.gif
    <package>/resources/login.gif
    Then in a Properties class I do this to get the properties:
    private static Properties getProperties() {
    Properties p = new Properties();
    try {
    p.load(getPropertiesInputStream());
    } catch (IOException ioe) {
    ioe.printStackTrace();
    return p;
    public static InputStream getPropertiesInputStream() {
    return CProperties.class.getResourceAsStream("App.properties");
    And to extract individual properties, something like this:
    public static String getReportDirectory() {
    Properties p = getProperties();
    return p.getProperty("Report.Dir");
    NB. Properties file entries should look like this:
    Report.Dir=/apps/reports

Maybe you are looking for

  • Opening sales order in new browser window

    hi experts, i have ALV table in which one of the columns is sales order number. I made the column as hyperlink so that user can click on it. when the user clicks on this i am calling an event handler method which is linked on_click event of the ALV i

  • Diff bet IDOC and Message Types.

    What are the difference between IDOC and Message types. Diff between MATMAS01 ,MATMAS02 and MATMAS03

  • Cannot view string from ApplicationResources in struts app

    Hello, I'm new to struts. I have added the following string to the ApplicationResources.propertiesfile : topic.label=Topic I am trying to display this label on the page without very much success. My page looks like this: <%@ page contentType="text/ht

  • Values not coming on export invoice

    Dear all, While creating Excise invoice for exports i am not getting excise values in document because i have not maintained condition types in Export pricing procedure. Now i have maintained Condition types in Export Pricing procedure both percentag

  • Messages generated by SMC

    Hi We have a customer with Sun Management Center 3.5.1b, the alert with sending message was configured, then they are process by Patrol to send messages by e-mail or/and SMS. We have a requirement for our customer: It's important to reduce the size o