Properties file in jar

When I build my application, I put the properties file in the jar file. I can easily read the properties file from there using
ClassLoader.getSystemResourceAsStream
but is there a way to actually UPDATE the properties in the properties file if it's included in the jar file I'm executing? Or, would I have to put the properties file outside of the jar to be able to update individual properties from within the code?

I would use the one inside the jar only if one externally does not work. If your jar is used by multiple users, you might want to store this in a place like $USER_HOME/.project_name/property_file so individual users can have their own properties. If the user has no properties, then load it from the jar.
If multiple users is not an issue, you could store it externally. I see no reason not to. You can store it internally, but you risk corrupting the original jar (say the power goes out while writing a new jar or updating it) You could do it with java.util.jar, or if the jar executable is available (or even a zip for that matter) you could call that to update the jar with the new properties file using Runtime and exec.

Similar Messages

  • Unable to find properties file in jar

    I have a jar file that looks like this from contents stand point
    c:> jar vtf csdsutility.jar
    0 Mon Oct 24 10:04:58 EDT 2005 META-INF/
    71 Mon Oct 24 10:04:58 EDT 2005 META-INF/MANIFEST.MF
    2633 Fri Oct 21 17:04:44 EDT 2005 csds/utility/JavaLogging.class
    1621 Fri Oct 21 17:04:42 EDT 2005 csds/utility/Logging.class
    868 Fri Oct 21 17:04:42 EDT 2005 csds/utility/LoggingMethod.class
    3204 Fri Oct 21 17:04:44 EDT 2005 csds/utility/TestLogging.class
    3004 Fri Oct 21 17:04:44 EDT 2005 csds/utility/Utility.class
    1142 Fri Oct 21 17:04:44 EDT 2005 csds/utility/WSLogging.class
    83 Tue Jul 26 21:59:26 EDT 2005 csds/utility/javalogging.properties
    If I include the jar file above in some other program it should find the
    javalogging.properties file correct? It's failing in the common code trying to find the properties file. I created a small driver that tests the common code and it is fine it just does not work off the jar file. Is there something weird about jar files and property files I don't know about? I thought when you included them on the java -classpath line it was like that code was part of your application and the path followed also.
    Thanks,
    Frank

    Are you using method getResourceAsStream? If so don't forget to properly add (or not) an "/" to the resource name as stated in Java API docs: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/".

  • Classpath problem with properties file in jar

    Hi,
    I am seeing a classpath error for my setup, as follows...
    A defaultFieldIDs.properties exists with numerous entries:
    projectID=10630
    issueTypeID=80
    closedStatusID=6My Spring applicationContext.xml file contains the following:
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
              <property name="locations">
                   <list>
                         <value>classpath:sqlScripts.properties</value>
                         <value>classpath:defaultFieldIDs.properties</value>
                    </list>
              </property>
              <property name="ignoreUnresolvablePlaceholders" value="false"/>
         </bean>     
    <util:map id="defaultQueryParameters">
              <entry key="projectID" value="${projectID}"/>
              <entry key="issueTypeID" value="${issueTypeID}"/>
              <entry key="closedStatusID" value="${closedStatusID}"/>
              <entry key="statusFieldName" value="${statusFieldName}"/>
              <entry key="numberOfExpenseLinesFieldID" value="${numberOfExpenseLinesFieldID}"/>
         </util:map>My compiled jar contains the above properties directory in its root directory, and is placed in the lib directory of the application
    However, when I start my application I get the following error:
    Invalid bean definition with name 'defaultQueryParameters' defined in null: Could not resolve placeholder 'projectID'
    What is going wrong here?

    Then presumably that jar file isn't in the classpath for your application. Perhaps just dropping it into the lib directory isn't sufficient.
    You didn't say anything about what kind of application it is. For web applications, all jars in the WEB-INF/lib directory are in the classpath. But you didn't say this was a web application and you didn't say you put it in the WEB-INF/lib directory. So if you don't care to put sufficient information into your posts, I recommend you read up on the rules for whatever type of application you have, in particular the rules for how to set its classpath.

  • Properties files in a Java package not included in DC build

    We are developing a Portal Standalone DC and i have a JspDynPage component within it. and i need to do internationalization in  it. so as part of that i want to keep multiple resource bundles(properties) so that i could manage my properties files easily, For example
    MSS.properties
    MSS_es.properties
    ESS.properties
    LSO.properties
    since portal by default has no way to do this bcos it allows only one resourcebundle to specify in portalapp.xml file, i have kept the resource bundles in java package like
    com.companyname.portal.resources.
    when i export from NWDS with selection of "i want to add non java resources into jar " option from windows->preferences->enterprise portal ->application development studio, it exports all the properties files as part of the par and everything works. but when i do the DC build it ignores all my properties files and it is not working. any suggestions on how to resolve this??? does SAP provide any other way of handling multiple properties files inside a PAR?????

    We are using NWDS 2004 SP19.  and yes i have defined three default SCs as dependencies. I tested with 2004s NWDS and it seems work fine. I am able to resovle this issue by moving my properties files into another java DC and create public part in java DC and use those public parts in Portal application DC.
    So The problem of not including the properties files into Jar seems to be issue only in Portal Application DC not in Java DC. thanks everyone for the quick responses..

  • Reading a properties file from BPEL Process (jar)

    Hello,
    I've created a .jar in which i have various classes and a xml file where i keep certain properties.
    I have a BPEL Process in which i've embedded java code to access the classes in the jar.
    I've created a folder in <ORACLE_HOME>/MyLibrary and added the jar. After, i've included this path to the domain.xml located in <ORACLE_HOME>/soasuite/bpel/domains/default/config into the property: "bpelcClasspath".
    When i try to run the process, i get a "<BPELExecution::BPELProcess1> executing <exec> at line 251
    java.lang.NullPointerException
         at java.util.Properties.loadFromXML(Properties.java:700)
         at com.gepe.ldap.LDAPConfiguration.readConfig(LDAPConfiguration.java:26)".
    Apparently the properties file is not being found, am i correct?
    How can i solve this?
    Thank's in advance,
    César

    Put your class files and proerties files here:
    $ORACLE_HOME/bpel/system/classes
    marc
    http://orasoa.blogspot.com

  • 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.

  • I18n JSTL / How to connect to new JAR holding new properties file?

    Hi there
    This is concering i18n and how (on earth;) JSTL knows where to find the according properties files that hold all the textual information.
    Okay. I have a piece of software that works fine and has the i18n mechanism running very nicely.
    I found the properties files in WEB-INF/lib/i18n.jar in a folder 'resources/bundle/'. They all prefix 'i18n' so JSTL makes use of them like this:
         <fmt:bundle basename="resources/bundles/i18n">
              <fmt:message var="thumbnailText" key="thumbnail.label" />
    So, we work on a new project right now based on this software. How can I add new project-related properties files?
    What I did:
    1) I created a new properties files having new textual information on new labels, etc.
    2) Put this in a folder of the new project JAR, which is in WEB-INF/lib now.
    3) Referenced the basename of fm:bundle according to this folder (including correct file prefix).
    -> Doesn't work.
    Is it that by convention all i18n information will be searched for in a JAR that must be named 'i18n.jar'?
    I'd greatly appreciate any hints
    Cheers
    André

    First, a sidenote to the SUN team: Before beeing able to reply, the forum denied me access unless I comitted to a screen name. Using my 'AndreKuhn' screen name got me 'Already in use'. Yes, of course. By me! So I had to pick AndreKuhn2 which is a little annoying. There seems to be something wrong with your system.
    Okay, back to the issue.
    Thanks evnafets for your notions! I have 2 JARs having i18n information. One had already been in use (successfully) by the underlying system. It's the one mentioned above ('i18n.jar'). Now there is a second one. Actually used the same way (technically) with different folders and namings. It goes like this:
    <fmt:bundle basename="resources/i18n/bdficp">
              <fmt:message var="titleText" key="publishLink.config.title" />
    With additional i18n information in 'WEB-INF/lib/<PROJECT-NAME>.jar'. Precisely in a file 'resources\i18n\bdficp_de.properties' having the line:
    publishLink.config.title=Just\ another\ title.
    Which should be the one referenced in the snippet above. Still the app gives me: ???publishLink.config.title???
    Any clue? I'd greatly praise your name across the rooms here!
    Cheers
    André

  • How to read properties stored in jar file

    Hello
    I got one question.
    I created properties file in my project, which contains some texts for panels. When I start application from JBuilder all works fine. This priperies file is stored in path "cmt/locales/CMTModule.properties".
    Problem is only in case I created jar file in which is this mentioned properties file. When I run through doubleclick my file ins't loaded.
    My procedure for load resource is follow:
    ResourceBundle res = null;
    private void initLocales() {
            String packageName;
            String className;
            String bundleName = null;
            String name = null;
            int index;
            try {
                packageName = this.getClass().getPackage().getName().toLowerCase();
                className = this.getClass().getName().toLowerCase();
                index = className.lastIndexOf(".");
                if (index > -1) {
                    className = className.substring(index + 1);
                bundleName = packageName;
                bundleName = bundleName + ".locales.";
                bundleName = bundleName + className;
    res = ResourceBundle.getBundle(bundleName);
                res = new PropertyResourceBundle(this.getClass().getResourceAsStream("locales/"+ className  + ".properties"));
            } catch (Exception exception) {
                System.out.println("Error to get local settings");          
            try {
                locales = new Locales(res);
            } catch (Exception exception) {
                exception.printStackTrace();
        }Whats wrong ?

    Thank You Very Much
    Problem was in case insensivite, because I'm convert class name to lower case. I only removed function toLowerCase().
    I replace these lines
    packageName = this.getClass().getPackage().getName().toLowerCase();
          className = this.getClass().getName().toLowerCase();with
    packageName = this.getClass().getPackage().getName();
          className = this.getClass().getName();Thanks

  • Adding a properties file into SapDictionaryTypesRuntime.jar

    Hi,
    I would like to add a properties file to SapDictionaryTypesRuntime.jar located in plugins\com.sap.dictionary.runtime\lib.
    Could you please help me how i can do  that ?.I tried using WinZip to add a file ,didnt help.

    This jar-file is part of the framework so you should not add anything to it.
    For testing purposes, you can extract the jar-file in its directory, add the property file to some folder and recreate the jar file using the jar-utility.
    Armin

  • [svn:fx-trunk] 11717: Bug Fixing Localized SDK - modified one file xercesSchema. properties in xercesImpl_ja.jar - added " to one JA string.

    Revision: 11717
    Author:   [email protected]
    Date:     2009-11-12 11:54:22 -0800 (Thu, 12 Nov 2009)
    Log Message:
    Bug Fixing Localized SDK - modified one file xercesSchema.properties in xercesImpl_ja.jar - added " to one JA string.
    ANT CLEAN MAIN successful
    Modified Paths:
        flex/sdk/trunk/lib/xercesImpl_ja.jar

  • I upgraded to Firefox 8. Now my home page says this: "Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/browserconfig.properties.

    This is what it says on my screen when I open Firefox:
    Firefox can't find the file at jar:file:///C:/Program Files (x86)/Mozilla Firefox/omni.jar!/browserconfig.properties.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Doubt on writing a properties file in to jar file

    hi,
    I have a jar file. In that jar file, I have a folder, named '/data/'. In this data folder i want to write a properties file. how to write?
    i was tried using the store method but i did not get it
    can any one help me out.
    thank you.

    You want to place the log4j.properties inside the .jar? You can read the log4j.properties inside the jar and give the Properties to log4j like this:
    String propertiesFile= "pathInJar/log4j.properties";
    InputStream in = getClassLoader().getResourceAsStream(propertiesFile);
    if (in != null)
        Properties props = new java.util.Properties();
        props.load(in);
        PropertyConfigurator.configure(props);
    else
       //PropertiesFile not found! (Handle the problem)
    }

  • Jar file and properties file

    Hi all,
    I have a jar file packaged as com.company.java located in $JAVA_HOME/jre/lib/ext. It will read a properties file when it is initialized. As I know, properties file needed to put under $CLASS_PATH. So I put it under $JAVA_HOME/jre/lib/ext also. However, the JAR file failed to load the properties file.
    Below is a part that in JAR file for getting properties file.
    ResourceBundle rb = ResourceBundle.getBundle("abc",Locale.getDefault());
    s=rb.getString("key1");
    } catch (MissingResourceException e) {
    s=null;
    e.printStackTrace();
    Do I put the properties file in wrong location?
    Where do I put it to make it work?
    Rgds,
    unplug

    by default you have 3 class loaders that load classes as well as read resources:
    The bootstrap classloader (for the core classes)
    The extension class loader (finds anything in any .JAR placed in $JAVA_HOME/jre/lib/ext/ [which is the home directory for "extension modules"])
    And the system class loader (looks along the classpath, finds files inside JARs [listed in the classpath] and in normal subdirectory structures [of base directories listed in the classpath] that mirror the hierarchy of Java packages)
    Any of these is supposed to consult the previous loader on the above list first, and try a lookup on its own only if the previous loaders did not find a class.
    ResourceBundle.getBundle(String, Locale) uses the classloader of its caller to look for the properties. If your method calling getBundle() was called from another method inside your extension module it will first consult the extension classloader (which first consults the bootstrap classloader) and will not be able to use the system classloader. So you can place anything in the classpath but it won't help. And the extension class loader can only look into JARs, not plain package directories.
    If the getBundle() method were called directly from the application code, however, it will use the system class loader to locate the properties file.
    There is a method ResourceBundle.getBundle(String, Locale, ClassLoader) where you can pass in e.g. the system class loader if you know how to get it, so this might help. The application code would determine its own class loader and pass it to the method of your your extension module.
    But I am not sure that you should place the properties file in $JAVA_HOME/jre/lib/ext/ since this is intended for Java extensions rather than normal user code, it normally does not show up on the classpath. Also, if you place it along the classpath, you have to pass in the classloader to be used since your code was loaded by the extension classloader and has no immediate knowledge of the system classloader.
    But perhaps it would be wiser to load your resource bundle reader in the system classloader, like any other application code: Remember that classes loaded by the extension classloader have higher security privileges than normal application code (the security policy file that you can edit refers to application code!) and it is questionable whether a resource bundle reader needs that privileges. If it does not, you might just place it in the classpath rather than the extension directory. Then it is quite natural that a properties file will also be found on the classpath.

  • How to update file in Jar using API

    Hi,
    I have a jar file (actually a war file), and I need to update the properties in one of the files before I deploy it.
    I have been able to open it, get the correct JarEntry, load the properties, update the properties, but am struggling to figure out how to save it back to the Jar file?
    Any ideas?
    cheers,
    David

    So why isn't your build process just creating thecorrect contents of that properties file
    before including it in the war it builds, in thefirst place?
    Because we deploy it in many customers. They will
    obviously have different ip addresses eg for the
    database machine.
    Therefore we have certain properties that are
    customer-specific we need to update in the war before
    we deploy it.
    cheers,
    DavidI wasn't implying that your build process is only run one time. The build process can be run each time you build for each deployment. So do you mean you only want to deliver one generic WAR to each customer, and you want this change of properties to happen on the customer side somehow? What code are you going to run on that side to change it - not code in your web app because at that point it's too late - you've already loaded the web app and its files, which this/these property files are a part of. Sounds like you need a "build process" to bundle up the app for each unique target.
    Alternatively you could investigate adding or altering the manifest file in the WAR (or EAR) file to reference an additional standalone, or loose, directory (outside the WAR/EAR structure) and put your property files there. Then that directory would become part of your app's classpath just like it were in your WAR/EAR, and you could update that file independently.

  • Unable to load properties file from filesystem

    Hi,
    I have a client swing-applicatiion packaged in a jar-file. The application uses some resource files, including a xxxx.properties file to set defaults for the application. All resource files are included in the jar file and everything works as expected. I load the xxxx.properties file as follows:
    is_ = getClass().getResourceAsStream("/resources/xxxx.properties");
    Because it is not possibl to change any property values inside the jar-file without recreating this jar-file, i want to exclude the xxxx.properties file from the jar-file and put it in the folder containing the jar-file.
    So i have:
    drive:/folder/app.jar
    drive:/folder/xxxx.properties
    Now i read the xxxx.properties file from disk in stead of the 'resouce'-folder within my application (jar):
    is_ = getClass().getResourceAsStream("drive:/folder/xxxx.propoerties");
    but it doesn't work, the file isn't found.
    What am i missing here?
    Any suggestions?

    The best way to approach this is to include the properties file in the Jar as you originally did. If the user changes any property, save the entire set of properties to a sub-directory of user.home (perhaps based on the package name of the main class). Check for the copy in user.home before using the 'default' properties built into the Jar.
    Other places/ways to store the changed information.
    - java.util.prefs.Preferences
    - Assuming the app. has a GUI and can be deployed over a network, the JNLP API PersistenceService. Here is a demo. of the PersistenceService (http://pscode.org/jws/api.html#ps).
    Edit 1:
    I did not at first notice that this post was in Java Applet Development.
    <li> Applets can also (theoretically) use cookies to store information. This is prone to failure when users disable cookies.
    <li> To store information on the local file system (e.g. in user.home) or to use Preferences (AFAIU) would require trusted code.
    <li> If the user has the Next Generation Java Plug-In (Java 1.6.0_10+) it is possible to leverage the JNLP API services in an embedded & sand-boxed applet.
    Edited by: Andrew Thompson on Feb 1, 2011 9:32 AM

Maybe you are looking for

  • Trim Transparency is not working in Photoshop

    I have a few of layers that have transparency, and I want to save them out as Transparent PNGs. For whatever reason when I saved it as a transparent PNG it is exporting it bigger than it should. It doesnt trim them to the non trasparent pixels, inste

  • 13" Retina MBP shutsdown no Crashlog

    Hi there, since last week after installing the EFI firmware update 1.1 my MBP has been randomnly shutting off, there are no crashlogs after the restart, the screen will go black and will take sometimes up to 3 mins to start the computer again. My gue

  • Dual Nic Load Balancing Solution

    Hi, I have a very peculiar situation. I'm currently a college student with access to an almost unlimited network. But the problem is that the network limits each IP to 30 Mb/s. I have 2 nics at my disposal and have tried two options so far: bonding t

  • Transferring bt internet email address

    I have recently closed my BT account as I have moved in with my girlfriend, who already has an account with BT.  I am concerned that I will shortly lose my btinternet email address.  Through another post on this forum and a conversation with BT about

  • Looking for job training

    Hello I hope you will  be generouse to advise me how can I find a job training with  flashbulder,php,mysql ??? I have searched for a month and got nothing to mention Thank you