How to load Java properties file dynamically using weblogic server

Hi,
We are using Java properties file in Java code. Properties in java properties file are frequently modified. If I keep these properties file in project classpath or as part of war, I will have to redeploy application after each change.
We are using Weblogic Server.
Can you please suggest me how can this properties file be loaded at weblogic server startup. Then in that case, how to refer property file in Java code?
What is the best practice for this?
Thanks,
Parshant

Another alternative is, keep the property file in any pre-defined location. Write a class which reads the properties from the file and returns the one which is requested by caller and deploy this class. Whenever you have to change the properties just update the property file on server and next call to fetch the property should return the updated one.
Downside of this approach is file I/O everytime. To overcome that you can actually "cache" the properties in a hashmap. Basically when any property if requested, first check the hashmap, if not found then only read from property file and also update in hash map. Next time same property will be returned from hash map itself. The hash map will be cleared at every server restart since its in the memory. You will also need to build a method to clear the hashmap when you update the values in the property file on server.
This solution would be suitable for small size files and when network overhead of calling a DB needs to be avoided.

Similar Messages

  • How to configure Java Properties File location in WLW

    How do we tell Workshop 7.0 where to look for Java properties files (loaded by
    PropertyResouceBundle in code) ?
    Thanks,
    Ray

    Ray,
    The build number indicates that you have not upgraded to Service Pack 2 of
    version 7.0. I will strongly recommend you to do so. That will shield you
    from the issues which were fixed in the 2 service packs.
    Regards,
    Anurag
    "Ray Yan" <[email protected]> wrote in message
    news:[email protected]...
    >
    Raj,
    We are using WebLogic Workshop Build 7.0.1.0.0829.0 on Windows 2000.
    We shut down the WebLogic Server on Solaris 2.6, log off, log back on,startWebLogic
    in production nodebug mode, and re-run jwsCompile on the same source code.The
    error does not occur anymore. Everything seems to be fine now.
    Thanks,
    Ray
    "Raj Alagumalai" <[email protected]> wrote:
    Hello Ray,
    Can you let me know if you are using the GA version of WebLogic Workshop
    or
    if you have the latest Service Pack.
    Thank You,
    Raj Alagumalai
    WebLogic Workshop Support
    "Ray Yan" <[email protected]> wrote in message
    news:[email protected]...
    Anurag:
    Thanks for your response!
    By moving the property files to WEB-INF/classes from WEB-INF, we arealmost there.
    But we have a follow up problem. We use a static initializer to loadthe
    log4j
    property file like this:
    static {
    try {
    ClassLoader cl= (new Log()).getClass().getClassLoader();
    InputStream is = cl.getResourceAsStream(logfile);
    Properties props = new Properties();
    props.load(is);
    PropertyConfigurator.configure(props);
    } catch (Exception e) {
    e.printStackTrace();
    When we run jwsCompile, we keep getting this:
    Compiling: com/****/TestWS.jws
    weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[weblogic.management.Admin
    may only be used on the Server ]
    at weblogic.management.Admin.getInstance(Admin.java:104)
    at
    weblogic.security.internal.ServerPrincipalValidatorImpl.getSecret(ServerPrin
    cipalValidatorImpl.java:79)
    at
    weblogic.security.internal.ServerPrincipalValidatorImpl.sign(ServerPrincipal
    ValidatorImpl.java:59)
    at
    weblogic.security.service.PrivilegedActions$SignPrincipalAction.run(Privileg
    edActions.java:70)
    at java.security.AccessController.doPrivileged(Native Method)
    at
    weblogic.security.service.SecurityServiceManager.createServerID(SecurityServ
    iceManager.java:1826)
    at
    weblogic.security.service.SecurityServiceManager.getServerID(SecurityService
    Manager.java:1839)
    at
    weblogic.security.service.SecurityServiceManager.sendASToWire(SecurityServic
    eManager.java:538)
    at
    weblogic.security.service.SecurityServiceManager.getCurrentSubjectForWire(Se
    curityServiceManager.java:1737)
    at weblogic.rjvm.RJVMImpl.getRequestStream(RJVMImpl.java:434)
    at
    weblogic.rmi.internal.BasicRemoteRef.getOutboundRequest(BasicRemoteRef.java:
    88)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java
    :255)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java
    :230)
    at
    weblogic.jndi.internal.ServerNamingNode_WLStub.lookup(Unknown
    Source)
    atweblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:337)
    atweblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:332)
    at javax.naming.InitialContext.lookup(InitialContext.java:345)
    at weblogic.knex.bean.EJBGenerator$1.run(EJBGenerator.java:101)
    at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManage
    r.java:780)
    atweblogic.knex.bean.EJBGenerator.lookupAdminHome(EJBGenerator.java:84)
    atweblogic.knex.bean.EJBGenerator.ensureAdminHome(EJBGenerator.java:122)
    at weblogic.knex.bean.EJBGenerator$6.run(EJBGenerator.java:660)
    at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManage
    r.java:821)
    atweblogic.knex.bean.EJBGenerator.generateJar(EJBGenerator.java:482)
    at
    weblogic.knex.dispatcher.DispJar.generateJar(DispJar.java:401)
    atweblogic.knex.dispatcher.DispCache.ensureDispUnit(DispCache.java:695)
    atweblogic.knex.compiler.JwsCompile.compileJws(JwsCompile.java:872)
    at
    weblogic.knex.compiler.JwsCompile.compile(JwsCompile.java:619)
    at weblogic.knex.compiler.JwsCompile.main(JwsCompile.java:109)
    ejbc successful.
    Generating EAR ...
    The EAR was generated and we can even deploy it on Solaris. But whatdoes
    the
    AssertionError mean?
    Thanks,
    Ray
    "Anurag Pareek" <[email protected]> wrote:
    Ray,
    ResourceBundle looks for the properties file in the current thread's
    classpath.
    Since a Workshop webservice's project is nothing but a webapp, the
    properties files can be kept in the WEB-INF/classes directory, which
    is part
    of the webapp classpath.
    You can also use
    Thread.currentThread().getContextClassLoader().getResourceAsStream("MyProp
    s
    properties"); to get access to the properties file.
    Thanks,
    Anurag
    "Ray Yan" <[email protected]> wrote in message
    news:[email protected]...
    How do we tell Workshop 7.0 where to look for Java properties files(loaded by
    PropertyResouceBundle in code) ?
    Thanks,
    Ray

  • How to load a properties file?

    Hello Everyone,
    We are experiencing difficulties when trying to load a properties file from a directory other then the one where the servlet is located. We are using the following code for this purpose:
    private final String PROP_FILE_NAME = "my.properties";
    Properties props = new Properties();
    try {
    props.load(getClass().getResourceAsStream(codeBase + PROP_FILE_NAME));
    } catch(IOException e) {
    //handle error ...
    where codeBase is either physical directory path to the properties file or the URL. In either case we get a NullPointer exception which means that file is not found. But when we copy the properties file into the same directory where the servlet resides, everything works fine.
    Does anybody have an idea as to how to resolve our problem?
    Any help will be greatly appreciated!
    Thanks in advance!
    Y.M.

    URLs try to address this issue for cross-platform file reference.
    I'd try doing something like:
    URL u = new URL(codeBase + PROP_FILE_NAME);
    props.load(getClass().getResourceAsStream(u));
    Regards,
    Eric

  • How to load a .properties file by giving relative path in a JSP file.

    Hey guys,
    I'm trying to load a .properties file in a JSP using relative path...
    It is not taking the properties file..
    What is the problem...?
    Any solution..?
    Thanks a lot.

    Yes I tried that also.
    Your path was something like this ?
    http://localhost:8080/Database/a.properties ?
    Whether this path will change after client installation ? if no then what's the problem ?
    For client side installation how you are going to set your conf directory for your application ?
    You are not going to give client installation page ?which will have all the values to be set like conf path. database,user name(s),log folder,temp folder etc ? Why you are keeping everything on server ?
    Check if this is useful,
    String context = request.getContextPath();
    String rmtAdd = request.getRemoteAddr();
    String host = request.getRemoteHost();
    out.println("http://"+rmtAdd+context+"<BR>");
    out.println("http://"+host+context);
    "http://"+rmtAdd+context
    Edited by: kanad on Jan 12, 2008 1:29 PM

  • Load balancing of DB RAC using weblogic server

    Hi All,
    I want to test the load balancing of Data base RAC for my application. I got the box which is installed RAC in it with two nodes. I configured the multidatasource which points to individual data sources to each node.
    Is this configuration is correct or not? to test the load balancing of the Database. I come to know that there is something called SCAN from oracle 11g but it is not supported 100% by web-logic server(we are using weblogic server 9.2MP3).
    How many requests I made all the requests are going to the Node1 only not even one is gone to the node2. Any specific reason.
    Thanks,
    Venkat.

    Another alternative is, keep the property file in any pre-defined location. Write a class which reads the properties from the file and returns the one which is requested by caller and deploy this class. Whenever you have to change the properties just update the property file on server and next call to fetch the property should return the updated one.
    Downside of this approach is file I/O everytime. To overcome that you can actually "cache" the properties in a hashmap. Basically when any property if requested, first check the hashmap, if not found then only read from property file and also update in hash map. Next time same property will be returned from hash map itself. The hash map will be cleared at every server restart since its in the memory. You will also need to build a method to clear the hashmap when you update the values in the property file on server.
    This solution would be suitable for small size files and when network overhead of calling a DB needs to be avoided.

  • How to load a .class file dynamically?

    Hello World ;)
    Does anyone know, how I can create an object of a class, that was compiled during the runtime?
    The facts:
    - The user puts a grammar in. Saved to file. ANTLR generates Scanner and Parser (Java Code .java)
    - I compile these file, so XYScanner.class and XYParser.class are available.
    - Now I want to create an object of XYScanner (the classnames are not fixed, but I know the filename). I tried to call the constructor of XYScanner (using reflection) but nothing works and now I am really despaired!
    Isn't there any way to instantiate the class in a way like
    Class c = Class.forName("/home/mark/XYScanner");
    c scan = new c("input.txt");
    The normal call would be:
    XYLexer lex = new XYLexer(new ANTLRFileStream("input.txt"));The problem using reflection is now that the parameter is a ANTLRFileStream, not only an Integer, as in this example shown:
    Class cls = Class.forName("method2");
    Class partypes[] = new Class[2];
    partypes[0] = Integer.TYPE;
    partypes[1] = Integer.TYPE;
    Method meth = cls.getMethod("add", partypes);
    method2 methobj = new method2();
    Object arglist[] = new Object[2];
    arglist[0] = new Integer(37);
    arglist[1] = new Integer(47);
    Object retobj = meth.invoke(methobj, arglist);
    Integer retval = (Integer)retobj;
    System.out.println(retval.intValue());Has anyone an idea? Thanks for each comment in advance!!!

    Dump all of your class files into a directory.
    Use the File class to list all files and iterateover
    the files.NastyNot really, when you are dynamically creating code, I would expect the output to be centralized, not spread out all over the place.
    >
    Use a URLClassloader to load the URL that isobtained
    for each file with file.toURI().toURL()(file.toURL()
    is depricated in 1.6)Wrong, the URL you give it must be that of the
    directory, not the class file.No, I did this quite recently, you can give it a specific class file to load.
    >
    Load all of the classes in this directory, thatway
    any anonymous classes are loaded as well.Anonymous classes automatically loaded when the real
    one isIt can't load it if it doesn't know where the code is. Since you haven't used a URL classloader to load once class file at a time, you would never encounter this. But if you loaded a class file that had an anonymous classfile it needed, would it know where to look for it?
    >
    From this point you should be able to just get a
    class with Class.forName(name)No. Class.forName uses the classloader of the class
    it's called in, which will be the system classloader.
    It won't find classes loaded by a URLClassLoader.got me there.

  • How to load a Properties file : Very URGENT

    I have properties file ie., SQLProperties.properties
    SQLProperties.properties
    logdetails = SELECT USERNAME AND PASSWORD FROM USER_TBL
    I want to load this file .
    I used like this
    public static Properties prop = null;
    strKey ="logdetails";
    FileInputStream fis = new FileInputStream("SQLProperties.properties");
    prop.load(fis);    // Since load parameter is file input stream
    prop.getProperty(strKey);But it is coming error while loading

    You did not initialize prop.
    //public static Properties prop = null;
    public static Properties prop = new  Properties ();
    strKey ="logdetails";
    FileInputStream fis = new FileInputStream("SQLProperties.properties");
    prop.load(fis);    // Since load parameter is file input stream
    prop.getProperty(strKey);
    [/prop]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to pick the sender files dynamically using the same File CC

    hi,
    My requirements is like , Same Sender File communication Channel has to pick up the different file which are having differnt file conventions and which are placed in different directories .. then it has to send to diffentn directories in the receiver side..
    how to do this?
    Regards,
    Balaji

    Hi Stefen,
    They have tried the Generic Sender File adapter concept to handle filenames with different names and from different directories instead creating many file channels. In my project many channels are configured as generic File sender channel.. And Eventhough the Generic file sender channels processing the filenames from different directories, all processed files are archieved in one common directories.. now they wanna generic solution to archieve the processed files in a particular folder based upon the directories they got processed from....
    and There are no such message mapping or Operation mapping since they used AAE concept. So do you  have any idea to make Generic File sender channels to archieve the files as per requirements i said before??
    Two doubts can we use like Module programming or can we do any OS level command acchieve this ? if yes please explain in detail .... Please help me out here
    please refer the following link .. exact way we used in our project
    http://wiki.sdn.sap.com/wiki/display/XI/SingleSenderFileCCForMultipleDirectories
    Regards,
    Balaji
    Edited by: Balaji Pichaimuthu on Feb 5, 2010 5:55 AM

  • How to load log4j.properties

    how to load log4j.properties file in my java code ?
    i have put log4j.properties in c:\property\log4j.properties directory.
    how do i load this properties file ?

    Normally you don't have to load it explicitely at
    all. Just place it in your classpath and use log4j,
    it should be loaded automagically.so, at run time i should use
    java -classpath .;c:\property\log4j.properties;c:\log4j.jar; MyClass
    is this the syntax ?

  • How to load an XML file to oracle9i server?

    I want to use XSU DBMS_XMLsave package to load an XML file to a relational table using PL/SQL from a distant server. Now, I don't know how to load that XML file to the distant server.
    Somebody help me?

    I want to use XSU DBMS_XMLsave package to load an XML file to a relational table using PL/SQL from a distant server. Now, I don't know how to load that XML file to the distant server.
    Somebody help me?

  • Java properties file

    Hi ,
    I am using trying to write data to a java properties file , by using the setProperty method and somehow the order of the data is not by the order of inserting it ,Is there a way to use the setProperty method and still keep the order of data in the file after storing it.
    Thanks.

    Eddie404 wrote:
    I am using trying to write data to a java properties file , by using the setProperty method and somehow the order of the data is not by the order of inserting it ,Is there a way to use the setProperty method and still keep the order of data in the file after storing it.It shouldn't matter what order the Properties class uses to write its data. If it does, you aren't doing something right.
    If the order matters, that suggests that somebody is responsible for maintaining the properties via a text editor, or something like that. In which case you shouldn't be using a Properties object which modifies the property file. But as soon as you start having two different processes to maintain the file, you're going to run into trouble. So simplify your life and stop doing that. Either maintain it through the program, or through the text editor, but not both ways.

  • How to Load a propety file (resources/toto.properties) in my jnlp ?

    Hi,
    I have to deploy a java application using JWS for the first time and i encounter a problem with my properties file.
    this is the story:
    I have a properties file which contains 1 line:
    repsrc = X:\\Documents and Settings\\aberghousse\\Bureau\\src\\When I deploy my application the jnlp can't open this file, this is the class that I use to load the properties file:
    public class LoadProp extends Properties {
         private static final long serialVersionUID = 1L;
         final static Logger log1 = Logger.getLogger(LoadProp.class);
         public LoadProp() throws IOException {
              // Read properties file.
              super();
              InputStream in = getClass().getResourceAsStream("/pathname.properties");
              try {
                  this.load(in);
              } catch (IOException e) {
                   log1.error("Load properties error", e);
              }finally {
                  in.close();
    }the pathname.properties is located in conf/pathname.properties and conf directory is in my CLASSPATH.
    In my sources to load a key I use this :
    File src = new File(new LoadProp().getProperty("repsrc ")So why this Exception :(
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at java.io.File.<init>(Unknown Source)
         at com.experian.IhmFdi.GetFiles.findFiles(GetPdfFiles.java:30)
         at com.experian.IhmFdi.GetFiles.<init>(GetPdfFiles.java:26)
         at com.experian.IhmFdi.Ihm.<init>(Ihm.java:99)
         at com.experian.IhmFdi.Ihm$16.run(Ihm.java:860)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Thank you for your help.
    null
    null

    yes perhaps no one know how we can to do, but i'm using URL class to load my file so I suppose that I have two mode
    1- offline : so i search file localy
    2- online : using URL
    this is a solution that works well for me I hope this help.
    aa
    Edit :
    this is an example : your source:
    URL prop = new URL(System.getProperty("propertyFile"));your jnlp file :
    <property name="propertyFile" value="http://ip:8080/conf/yourfile.properties"/>Edited by: Aberghouss on Jan 7, 2008 2:33 PM
    Edited by: Aberghouss on Jan 7, 2008 2:35 PM

  • How do I load a properties file that is in the same package?

    I have the following package:
    com.company.ldap
    In the package I have:
    main.java
    settings.properties
    I want to load the values in the settings.properties file in code, such as:
    propertiesFile = "settings.properties";
            try {
                properties.load(new FileInputStream(new File(propertiesFile)));
            } catch (IOException e) {
                ... error logging logic ...
            }I keep returning "The system cannot find the file specified".
    How do I properly load a properties file in a class file within the same package?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Put the file in the classpath (such as in the parent directory of com/company/ldap). Then obtain an input stream to that file like this:
    InputStream stream = getClass().getResourceAsStream("/settings.properties");
    Then use that stream in the properties.load method. Remember to close the stream as well.

  • Need help for how to putting arabic content in java properties file

    Hi all,
    we have to support arabic in Java application.
    For that we are using java propeties file where key and value pair is used.
    In the Microsoft excel sheet arabic content is coming properly from right to left direction.
    When same thing is copied and paste in java properties file contents direction is reversed that is it is coming from left to right as in english.
    Please help how to put the arabic contents in propeties file
    Regards
    Vidya

    So in terms discussion.
    First I would suggest that you get a hex editor and validate exactly what is in the properties file. It appears to me that you are using one or more editors that are adjusting the display for you and thus that makes it hard to determine where the problem is. A hex editor should not adjust the display. Although even then you might want to right a simple java app and have it read bytes and print them just to validate that the hex editor isn't doing something.
    Only after you are exactly sure how the bytes appear in the file then proceed with other steps.
    For the java GUI only test the following.
    1. Properties file has it left to right then the java GUI displays it correctly right to left or not?
    2. Properties file has it right to left then the java GUI displays it correctly right to left or not?
    Myself I would expect that 2 should be the correct way to implement this. However that is dependent upon you correctly invoking the api as well. So if 2 is not working then you might want to look at the api. It might also have something to do with GUI display properties (of which I know even less.)

  • How to load a client file in a clob using sqlcl

    How to load a client file in a clob using sqlcl

    You don't "load" jars. If it's on the classpath, you can obtain individual resources from it using various methods on either Class or ClassLoader. Do you mean "how to add a jar to the classpath at runtime"? Can't be done without using a classloader, typically URLClassLoader or a subclass thereof. Why you want to not use the proven method is beyond me. Presumably because you don't understand classloading. In which case, forget it.

Maybe you are looking for

  • Print pdf reports

    New to Portal. How do I add the option to print a generated html report as pdf ?

  • Speakerphone dynamics.....Just a thought.

    I wonder - is the volume problem with the speaker phone Apples way of handling feedback? With my limited experience with sound reinforcement depending on where you set a mic and a speaker and what they are facing could change their characteristics. W

  • ITunes deletes all the music off of my iPod. Why?

    iTunes is being a huge piece of crap. I want it to sync my songs onto my iPod Touch 4G. Instead, it decides to delete all 5500+ songs off of my iPod... twice. Once, I managed to put the songs back on, this takes over an hour and a half, then it delet

  • Compression Time: 90 vs. 120 vs. 150

    Hope this is a simple question: When using compressor to compress video for DVD, can anyone answer the question as to whether different compression settings take longer? Not asking about single encode vs. best quality, but specifically: Does it take

  • Forms from A to Z

    Anyone know of some good tutorials for building forms from beginning to end? I can design the form in Dreamweaver but don't understand how to get the form filled out and sent to me online. Anyone know of an idiot proof tutorial or explanation i would