Use properties file in Struts framework

I develop a websit with struts, web ap is tomcat5.0, and I have a conf.properties file
this file is different from ApplicationResource.properties, conf.properties in the /MySite/conf/ directory, not in src directory
When I Use the conf.properties file in a Common Java Class that not extends any super class
it will occur a FileNotFoundException exception
How to make it
public class Environment
     private static Properties prop = new Properties();
     private static FileInputStream in = null;
     public static String getVariable(String key)
          try
               in = new FileInputStream(new File("\\conf\\config.properties"));
               prop.load(in);
               return prop.getProperty(key, null);
          catch (Exception e)
               e.printStackTrace();
               return null;
          finally
               try
                    in.close();     
               catch(Exception e)
                    e.printStackTrace();
     }

Your class cannot find the file in the location tht u have given. The path (\\conf\\config.properties) is relative to the location where your source (Environment class) is kept.
Try to hard code the path & see if your source can find the prop file ...

Similar Messages

  • Using Multiple Properties Files in Struts Framework

    Hi Everybody!
    I just to know how to use a multiple message-resources files in a Struts Framework.
    I've 2 properties file :
    1. ApplicationResources_A.properties
    2. ApplicationResources_B.propertiesI put the files under WEB-INF/classes dir.
    My configuration in struts-config file something like below:
    <!--  Begin Testing -->
         <message-resources key="A" parameter="ApplicationResources_A" />
         <message-resources key="B" parameter="ApplicationResources_B" />
    <!--  End Testing -->
    </struts-config>
    if my JSP code is like below , this error is thrown:
    org.apache.jasper.JasperException: Cannot find message resources under key A
      <tr>
        <td width="17%">Language A</td>
        <td width="83%"><bean:message bundle="A" key="user.lang.desc"/></td>
      </tr>
      <tr>
        <td width="17%">Language B</td>
        <td width="83%"><bean:message bundle="B"  key="user.lang.desc"/></td>
      </tr>
    but  if I change the  JSP code like below it  work fine:
      <tr>
        <td width="17%">Language A</td>
        <td width="83%"><bean:message key="user.lang.desc"/></td>
      </tr>
      <tr>
        <td width="17%">Language B</td>
        <td width="83%"><bean:message  key="user.lang.desc"/></td>
      </tr>
    In this code , I dont know  which resources file is used.
    So how do I solve this problem. Thanks you.

    I have defined the following:
    struts-config.xml
    <message-resources key="ldap" parameter="com/project/struts/ldap"/>
    Action.java
    In execute method:
    MessageResources messageResources= MessageResources.getMessageResources("com/project/struts/ldap");
    System.out.println("INITIAL_CONTEXT_FACTORY"+messageResources.getMessage("INITIAL_CONTEXT_FACTORY"));
    and it is working, however I have to change "com/project/struts/ldap" value in Action.java file whenever there is any change in name or location of ldap.properties.
    Can I access this properties in such way that I don't have to change parameter path manually in Action.java (modifying in struts-config.xml is okay)? like access through key="ldap" or something.
    Thanks and regards,

  • How to use properties file

    Hi,
    I want to use properties file in my application. I have kept properties file inside a directory called properties which is inside myProject(which is the parent directory of my project) i.e "myProject/properties".
    My java file where i want to call this properties file is inside the myProject/WEB-INF/src/java.
    How can i call the properties file from myProject/WEB-INF/src/java/PropertyReader.java
    I wrote java program in myProject/WEB-INF/src/java/PropertyReader.java like:::::
    ResourceBundle resBun = ResourceBundle.getBundle("Test", Locale.getDefault()); // Test.properties is inside myProject/properties
    resBun..getString("name");
    After running the program i am getting the following errors:::::
    Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Test, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
    at PropertiesReader.main(PropertiesReader.java:4)
    What is the issue? How to use properties file?
    Waiting for reply.
    Thanks

    Still getting same exception. As you explained i tried like the below:::
    1. I am using ant as build tool.
    2. My properties file is for database configuration
    My properties file is::
    database.properties (inside myProject/properties)
    JDBCDriver=org.gjt.mm.mysql.Driver
    JDBCConnectionURL=jdbc:mysql://pmdbmysql:3306/bandwidthshaper?user=admin&password=admin
    My java package structure is
    WEB-INF/src/java
    WEB-INF/src/classes
    For build WEB-INF is the base directory and build.xml is inside the src directory
    In my build.xml i wrote the following lines for compilation::
              <target name="compile" >
                   <javac srcdir="src" destdir="src/classes" debug="true" debuglevel="lines,vars,source">
                        <classpath refid="class.path"/>
                   </javac>
    <copy todir = "src/classes" >
    <fileset dir = "../properties" />
    </copy>
                   <jar jarfile="lib/${project.jar.file}" basedir="src/classes"/>
              </target>
    I am copying properties file to the classes directory.
    Now in java file which is inside /WEB-INF/src/java, I wrote::
    try {
    Properties programProps = new Properties();
    InputStream is = getClass().getResourceAsStream("/database.properties");
    if(is == null)
    throw new IllegalStateException("Properties file missing ");
    programProps.load(is);
    System.out.println("driver name::::::: "+programProps.getProperty("JDBCDriver"));
    is.close();
    } catch(Exception e) {
    e.printStackTrace();
    After compilation in my classes directory i am getting database.properties file and my java file with package.
    At the time of running i am getting "java.lang.IllegalStateException: Properties file missing"
    Now tell me where is the fault. Why again i am getting exception.
    Thanks

  • How to use .properties files in Webdynpro Java code?

    Hi all,
      I want to use a logon.properties file when I initial a JCO connection pool in my webdynpro DC (JCO.addClientPool()),but  I found when I deployed this DC to the server, it always giv e me an FileNotFoundException. So I donot know how to deploy a .properties file to the server and how to access this file in my Java code?
    Thans and Best regards
    Deyang

    Hi,
    1) put .properties file to your packege under src\packages folder (src\packages\com\sdn\properties\jco.properties)
    2) load property:
         final InputStream is = getClass().getClassLoader().getResourceAsStream("com/sdn/properties/jco.properties");
         final Properties properties = new Properties();
         try
              properties.load(is);
         catch(Exception e)
              wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    Regatds Maxim R.

  • Using .properties file in web dynpro

    Hi,
    I am having a requirement. I have to create a .properties file and I have to use it in my web dynpro application. How can I do that? Any help...
    Thanks & Regards,
    Raj

    Hi,
    Go to the navigator view...select src\Components\<ComponentName> and create create a .properties file.
    You can read the  configuration file in your webdynpro app as follows
    IWDConfiguration configuration =
          WDConfiguration.getConfigurationByName(
            wdComponentAPI.getDeployableObjectPart(),
            "<<>>");
    http://help.sap.com/saphelp_nw04/helpdata/en/b8/aa343e32ff1033e10000000a114084/frameset.htm
    Regards, Anilkumar
    Message was edited by:
            Anilkumar Vippagunta

  • When to use properties file

    On navigating into any web application there wil be some .proeprties file (build.proeprties, applicationResources.properties etc..) and some .xml files(web.xml, struts-config.xml). Why .properties file why not all in XML ??

    The question should be: why XML and why not a properties file? XML is lots of overhead for simple tasks.

  • How use properties file

    Hi i read about properties file in java .. i didn't get much more..
    how can we use this in program.. what is the benefit..
    anyone know any examples in site.please let me know about that

    int count=getGoogleSearchCount();
    public int getGoogleSearchCount(){
    search keyword="http://www.google.co.ke/search?hl=en&q=java+properties+class&btnG=Google+Search";
    // missing code
    return count;
    System.out.println(count);i ran the above code snipplet and guess the output?
    291,000 results.
    DONT BE LAZY.

  • How to read multiple files at multiple locations using properties file

    hi all ,
    in my code i take configuration input from a properties file ,it was really easy but what if there are multiple files ? how can i take configuration input (file path etc) from properties file in that case ? any suggestion ?

    thanks :) ..i am doing like this :
    String fName[]=new String[10];
              String choice[]=new String[10];
              String Delim[]=new String[10];
              ResourceBundle a = ResourceBundle.getBundle("input");
              String n=a.getString("NOF");
              try
                   for(int i=0;i<Integer.parseInt(n);i++)
                        fName=a.getString("PATH"+(i+1));
                        choice[i]=a.getString("HEADER"+(i+1));
                        Delim[i]=a.getString("DELIMITER"+(i+1));
                        putData(fName[i],choice[i],Delim[i]);//to put data in database
              catch (NumberFormatException e)
                   System.out.println("Number of files are invalid");
    hope this method would be fine ....again thanks for the advice :) :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Use properties file out of EAR

    HI All,
    Generally we create an EAR file with all the property files embedded in it. Here the problem is as and when we change the property files we need to build a new ear file and redeploy to J2EE stack.
    Is there any way that this properties file is out of EAR application and changes done to the property file reflects in EAR? So that, no need to redeploy the application again and again. Means dynamic reflecting of property changes to already deployed EAR application. How it can be done?
    Actually this is our client requirement also...
    Hope am clear.
    Regards,
    Satish.

    Hi,
    There are ways to achieve this.
    I guess you can try following.
    You can define properties file in another project (like java project) and then include that project as a reference in your EAR application.
    Ashutosh

  • Can I use DynaActionForm/DynaValidatorForm of Struts Framework as a POJO cl

    Hi everybody,
    I am using hibernate with struts. So please tell me how can I use DynaActionForm/DynaValidatorForm as POJO class of hibernate. How should be the OR mapping file? I mean what should be in place of ? (question marks) below?:::
    <hibernate-mapping>
    <class name=? table="ELEMENT">
    ..

    You already asked that here:
    http://forum.java.sun.com/thread.jspa?threadID=5200392&messageID=9800476

  • Oracle portal using JSF, JSP, Struts framework

    Hi ,
    Can anyone tell me how to build an oracle portal using JSF,Jsp and Struts Framework.
    Also please provide any manual or documentation for developing oracle portal.
    Thanks in Advance,
    Raghav

    At present, i think the best thing to do is to look at the example provided with the struts-faces integration taglib. I don't know any documentation about it.
    http://cvs.apache.org/builds/jakarta-struts/nightly/struts-faces/

  • How to implement Dynamic properties files?

    Hello,
    I use Properties files to display some messages in my jsp but It could be very usefull if someone can tell me a way to reload my properties files when my application server is running.
    Or if Someone can tell me where to find the singleton who manage the map of message it can help me a lot ^_^.
    NB: I use Struts framework to manage properties, but if someone have a solution with JSTL I'm interest too.
    best regards,
    J�r�me

    Hi Jerome, this is something all Java developers have run into at some point I believe. The ResourceBundle in Java reads your .properties file once and cannot be told to re-load. Unless you can do some sort of classloader trick, not sure.... You have a few options otherwise:
    1) Write your own ResourceBundle which either checks a database or re-reads a .properties file on some timely basis.
    2) Use Spring's ReloadableResourceBundleMessageSource (http://www.springframework.org/docs/api/org/springframework/context/support/ReloadableResourceBundleMessageSource.html) The only drawback here being you no longer use the ResourceBundle like you would a normal Java resource bundle (i.e. using ResourceBundle.getBundle()) you now use Spring's MessageSource interface to get at your properties.
    Hope that helps

  • .properties file in servlet classpath

    I have a servlet that I trying to run under OC4J/Orion here at
    Oracle. The servet is trying to load it's property file
    with:
    InputStream is =
    ClassLoader.getSystemResourceAsStream("ipruntime.properties");
    But the inputStream is always null no matter where I put the
    properties file in the classpath (I've tried putting it in
    jars or in a directory). The servlet is invoking methods in
    other java classes just fine, so there is not a problem with
    the classpath.
    Any clues of what might be wrong?
    The same servlet with it's property file in the classpath runs
    under Apache/Jserv just fine.

    InputStream in =
    this.getClass().
    getClassLoader().
    getResourceAsStream("theFile.properties");
    I think the general advice is to use 'this.getClass()' to make
    sure which ClassLoader is being called.
    This may not be a problem, but try it?
    If you're deploying on OC4J you might also want to try one of the
    'newer' methods of 'using properties files', ie: put it in
    web.xml and look it up.
    Cheers,
    Malte

  • Character encoding problem with german umlaut in propertie files

    Hi,
    I use propertie files to translate application to multiple languages.
    These files contains german umlaut (e.g.: Wareneingänge).
    If I rebuild my application then this files are copied from ../src/view to ../classes/view.
    The file in ../classes/view contains "Wareneing\ufffdnge" instead of "Wareneingänge" which is displayed as "Wareneing�nge".
    My browser-, project- and application settings are UTF8.
    Previously the settings for project and application where "Windows-1252"
    I have found an workarounds but maybe this is a bug in Jdeveloper TP4.
    Therefore I post this problem. Maybe someone can confirm this behaviour.
    Workaround:
    Replace "Wareneingänge" with "Wareneing\u00e4nge" in the ../src/view file
    (Zaval JRC Editior does this for you :-) )
    regards
    Peter

    Hi,
    I think to remember that the same was required for properties in 10.1.3 as well. Not sure if this is an issue in JDeveloper 11. I'll take anot and have a look though
    Frank

  • Usin properties file in bpel

    Can I use properties files with bpel (if can how it does?)
    for tune some region options

    You could write a custom xpath function and plug-in to the bpel engine to do this job.
    The custom xpath function can read a property file and convert into a xml element and use that xml element inside bpel.
    The tricky part is to map the properties file into a xml schema and convert the properties file into xml document. Inside bpel, the variables refer to xml elements.
    Another easy solution is to use java <exec> to do the same.
    -read file
    -change your mail/portal data inside the java exec using setVariableData() function.

Maybe you are looking for