.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

Similar Messages

  • UNable to locate Properties files from Servlets

    I have a Web App deployed in the default domain (domain1)that contains a servlet which needs to read in values from a .properties file from the filesystem. However, whenever I try to use it, I always end up with a FileNotFoundException.
    I tried keeping the properties file in the d:\Sun\AppServer7\bin as well as d:\Sun\AppServer7\domains\Domain1\server1\bin and still get the same exception.
    Can anyone tell me where I need to keep the .properties file? FYI, I have deployed the same on Tomcat 4.x and the same app worked perfectly (with the prop file in d:\tomcat4\bin directory).
    Thanks,
    Chetan

    Try the instance config directory. In your case, this is probably D:\Sun\AppServer7\domains\domain1\server1\config.

  • Even after classpath setting in jserv.properties file  error.

    hi kali,
    i have used a custom jsp page for export to excell using a jar file poi-3i-200566.jar which i deployed in oracle apps version 11.5.10.2.
    the jar is put in $JAVA_TOP and class path entry is set in jserv.properties file as
    wrapper.classpath=/d2_u10/....../poi-3i-200566.jar .
    After setting the classpath , bounced the apache.
    But even after the setting , the same error continues.
    I refered the mod_jserv.log file for error details , the error is in import statement of classes present in the poi-3i-200566.jar file like
    could not find the symbol HSSRow , HSSpreadsheet , etc. all these are classes in jar file.
    please anybody know any extra conf is needed or any idea where i am going wrong.
    thanks
    prabhakr,ap

    Hi,
    Please check your jserv.properties file whether the custom class path that you have set is present or not in jserv.properties after restarting the AutoConfig and Apache server.
    Thanks & Regards,
    Sagarika

  • PLEASE HELP. How do you access properties files in WEB-INF  and classes directory

    We have a war file that needs to access properties files that are in the WEB-INF directory
    of the war file. We also need to load one of the properties files from the classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjar and a
    war and the libraries both the ejbjar (with a manifest setting the classpath ) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path "WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO properties files
    have been extracted into their appropriate places ( not even those we throw into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves

    The file doesn't have to be extracted from the war. For example, you can place
    test.properties into your app WEB-INF and write a simple JSP to see how it
    works:
    <%
    InputStream in = application.getResourceAsStream("/WEB-INF/test.properties");
    %>
    It will return you a zip inputstream if you deployed your application as a .war.
    Christian Hargraves <[email protected]> wrote:
    I try this, but I get a NullPointerException. The file never actually gets extracted
    from the war. Under tomcat and resin this works great ( that's why I am having all
    of the trouble i am having ), but there are absolutely no properties files in the
    extracted directories for WebLogic deploys. only:
    WEB-INF/some_tmp_dir/WEB-INF/lib
    and then some dynamically generated jor file with all of the classes that would normally
    go in WEB-INF/classes ( all except the properties, of course, which are no where
    to be found. ).
    There has to be some kind of setting I am missing. Please don't make me seperate
    these properties files from the war/ear and then put the path to these properties
    files in the CLASSPATH, changing one step to three steps to deploy!!
    I have found a documented bug where you can't even put the properties files in a
    jar file and that bug will never be fixed for WebLogic 6.1.
    "Dimitri I. Rakitine" <[email protected]> wrote:
    To access files in WEB-INF you can use ServletContext.getResourceXXX("/WEB-INF/filename")
    Christian Hargraves <[email protected]> wrote:
    We have a war file that needs to access properties files that are in theWEB-INF directory
    of the war file. We also need to load one of the properties files fromthe classpath.
    However, when we deploy the application ( an ear which inlcludes an ejbjarand a
    war and the libraries both the ejbjar (with a manifest setting the classpath) and
    war need ) the properties don't get extracted.
    In some of our servlets we are trying to access those files with the path"WEB-INF/foo.properties"
    and we get a FileNotFoundException. Then we check and see that NO propertiesfiles
    have been extracted into their appropriate places ( not even those wethrow into
    the WEB-INF/classes directory ).
    PLEASE HELP,
    Christian Hargraves--
    Dimitri
    Dimitri

  • Placing properties file

    wls 6.1sp4
    WebApp in WAR format contains a servlet which loads on startup. This servlets
    has to load some properties file. Currently if i have this properties file in
    system classpath. Servlet is able to find. I dont want to place my properties
    file in system classpath.
    i tried placing in web-inf/classes and checked preferwebinf classes. But still
    no luck. when servlet is loaded and trying to find the resource bundle..it is
    unable to find it.
    any pointers will be appreciated very much.

    Copy resource bundle of the default locale to the web-inf/lib directory.
    ResourceBundle resourceBundle=
    ResourceBundle.getBundle(myResourcesFile, Locale.getDefault(), getClass().getClassLoader());
    "yo" <[email protected]> wrote:
    >
    "Deepak Vohra" <[email protected]> wrote:
    Get properties file with the getResourceAsStream() method.
    Copy properties file in the WEB-INF/classes directory.
    InputStream inputStream =
    getClass().getClassloader().getResourceAsStream("servlet_properties.properties");
    props.load( inputStream );
    I forgot to mention that it is not properties file. it is resouce bundle.
    I have
    place resournce bundle in web-inf/classes folder.
    in my servlet, im using
    ResourceBundle.getBundle(myResourcesFile, Locale.getDefault(), getClass().getClassLoad());
    but im getting
    MissingResourceException
    any pointers
    >
    "yo" <[email protected]> wrote:
    wls 6.1sp4
    WebApp in WAR format contains a servlet which loads on startup. This
    servlets
    has to load some properties file. Currently if i have this properties
    file in
    system classpath. Servlet is able to find. I dont want to place my
    properties
    file in system classpath.
    i tried placing in web-inf/classes and checked preferwebinf classes.
    But still
    no luck. when servlet is loaded and trying to find the resource bundle..it
    is
    unable to find it.
    any pointers will be appreciated very much.

  • How to give Path for a properties file

    Hi,
    I am using a SQL.properties file to load all my SQL statements to my EJB JDBC prepared Statement. I have placed the SQL.properties file in com.company.sql package. I have another SQL class in the same package which is loading the SQL.properties file to cache for future use. I am using the path as "SQL.properties" (the file name straight ) in the SQL class to access the properties file.
    I am using Sun App Server 7. To get access to this file I need to copy the SQL.properties file to the config directory of the app server instance. Otherwise it is not able to locate the file. I don't want to put the properties file in the config directory of the app server instance. Please help me, what path I have to give to access the file from the package itself, rather from the config directory of server instance.
    I think , some one who is doing localization can help me out here. They have to put the localized properties file to access the text out of it. Please help me. Thanks in advance.
    Thanks
    Amit

    You can use ResourceBundle class to load this properties file from the classpath:
    ResourceBundle props = null;
    props = ResourceBundle.getBundle("com.company.sql.SQL");

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

  • Configure properties file that java file uses in OSB.

    I have a jar file consisting of java files which maintain the session id in the queue. One main jar depends on 3 more jars for logging.
    Also java files in the jar depends on the *.properties file to read the queue length dynamically.
    I need to access the main jar from osb proxy server. I used java callout to access the java method provided in the main jar.
    My question is: where should I place *.properties which is used by java class, in the osb folder. I don't see how I can add *.properties in the osb console.
    Your timely help is greatly appreciated.

    sudheshna wrote:
    another java class which loads property file...I'm understanding that you don't have way to modify this +"another java class"+, but you have to figure out what strategy it uses to pick up the properties file... classpath? environment variable? absolute path? relative path?
    If the file needs to be on the classpath (a common strategy) then you can just place the it in %DOMAIN_HOME%\config\soa-infra... This one is usually in the classpath... Other option is to change setDomainEnv.cmd(setDomainEnv.sh) to add a directory to the classpath and place the file there...
    Hope this helps...
    Cheers,
    Vlad

  • Japanese unicdoe properties file

    I have a japanese resource bundle file in SJIS encoding (*.properties)
    I used native2ascii from JDK and convert SJIS to unicode.
    Then read japanese ( in unicode properties file ) from servlet and send to IE browser.
    but IE will display all "?" s
    On the other hand it display correctly if I use SJIS encoded properties file. ( which has a problem -- all SJIS character with "/" character will need to manully escaped "//" )
    I wonder why unicode properties file doesn't work?? I thought we should always convert properties file to unicode to avoid the escape problem of "/" character.
    thanks

    Regardless of charset, all HTML files should begin with an appropriate charset meta tag.
    The JSP for this:
    <%@ page contentType="text/html;charset=UTF-8" %>
    The HTML for this:
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    What charset encoding are sending to the IE browser? Is it UTF-8? UTF-16? something else?
    Regards,
    John O'Conner

  • How can configure .properties file and  log4j on weblogic 8.1 SP5

    Hi,
    I know this is not right forum for post this question.But I hope I'll get my perfect answer here.
    I have 2 questions.
    1. Where I'll keep my .properties file in weblogic 8.1 SP 5. means I have one own .properties file which is contains some proxy settings and this .properties resides on .war file(now), But I want move this propeties file outside .war file. So Where I'll keep in weblogic 8.1 SP 5.
    2. How can we configure log4j in weblogic?
    Please reply me.
    Regards,
    Pattanaik

    You can add your.properties and log4j.properties to the classpath cant you?
    You just need to edit setEnv.cmd (if i remember correctly) in your weblogic server folder to add the folder containing the properties files to the classpath variable.

  • About properties file

    Hi Guys,
    I have a major doubt about '.properties' file.
    I thought if a '.properties' file exists anywhere in the classpath, it should be picked up by any application.
    But most of the time, eventhough it's in the classpath, '.properties' file is not found picked up at all.
    Is that my understanding about this is wrong or is there anything else I need to do to make the '.properties' file visible to all applications?
    what could be wrong?
    please enlighten me on this.
    Thankx in advance..
    Manesh

    you need to use the resource bundle facilities. I don't think so. I think the following will load a properties file using the classpath. It doesn't use a ResourceBundle.
      Properties aProperties = new Properties();
      static final String MAIN_FILE_PATH="./resource/mine.properties";
      // This should find 'mine.properties' on the classpath.
      // It will search each dir in the class path adding
      // MAIN_FILE_PATH to the end of each dir.
      // It will replace the path seperator if needed (win os.)
      java.io.InputStream is;
      is = ClassLoader.getSystemClassLoader().getResourceAsStream(MAIN_FILE_PATH);
      if (is == null)
        throw new Exception("Resource File "
          + MAIN_FILE_PATH + " not found.");
      aProperties.load(is);

  • Over riding a properties file?

    Is there a way to pass a new properties file on the command line that will over-ride a properties file embeded in the jar file?
    Our deployment would otherwise involve creating multiple copies of one jar file with slightly different properties files (and this is 3rd party so I can't get the devs to change it).
    Cheers,
    Seigers

    Hmmm, I'll assign the dukes, but it wasn't a world changing answer - RTFM for dukes is a bit cheeky!
    The correct answer appears to be that if we copy the properties file from the jar to the deployment directory and delete it from the original jar file, so long as we put the deployment dir in the classpath the new properties file will be picked up.
    E.g.
    c:\product\javalibs\myjar.jar <- Contains 'myprop.properties' on install.
    Use zip to extract myprop.properties and copy it to say c:\myproject\props\
    Use zip to delete myprop.properties from the jar file and include c:\myproject\props\ in your classpath.
    Java will then find the properties file from the classpath when it can't find it in the jar file.
    As intended you can now copy the properties file to c:\mynextproject\props and modify it then include it in that deployments classpath and you have one app install with multiple properties.
    In fact no, I'm not going to award the dukes as the Jar command wouldn't even begin to help solving that lot (except arguably the extract of the props file).
    Hope the above helps someone else as well as me.
    Cheers

  • Fail to load properties file

    Hi
    I can't load properties file. Please help!
    my setting is listed as follows:
    My properties file "kpggc.properties" is stored in the path : W:\kpggc\KPGGCWorkspace\KPGGCProject\src\hkpost\kpggc\client\resources
    I have already add the above path into the classpath and my application is a standalone application. I use the following codes to load the "kpggc.properties" file:
    private static boolean getProperties()
    Properties properties = new Properties();
    try
    properties.load(new FileInputStream("kpggc.properties"));
    catch (IOException e)
    System.out.println("Cannot find the properties file 'kpggc.properties'");
    catch (Exception e)
    System.out.println(e.getMessage());
    After running the above method, error message "Cannot find the properties file 'kpggc.properties'""always show.
    Thanks in advance.

    there is a way. u need not give the complete path of ur file.
    include the path of the properties file in ur classpath.
    in ur code, do the following:
    (inputStream and properties are declared before this code.)
    inputStream = ClassLoader.getSystemResourceAsStream(fileName);
    properties.load(inputStream);
    regards

  • Reading a properties file in a servlet and passing its contents to a JSP pa

    Hi all,
    I'm totally new to Servlet pgmg n JSP. Please can ne1 tell how to read a simple properties file (in a servlet) and pass its contents to a JSP page.Actually the reason is to fill a combo box in a JSP page with the contents of a properties file.If calling a servlet for the same is d best way to do that, plz can ne1 tell me :
    1> whether to override the doPost method in the servlet in which to read d file using FileInputStream
    2> Putting the contents in an array and then how to pass this array to the JSP page.
    Thanks,
    deepthy.

    I'm using a properties file to let my web application know what the name of the database is. I'm using an abstract class GeneralDao which will be extended by all the DAO's (Data Access Objects or java classes containing SQL statements).
    Here's the code :
    protected Connection getDatabaseConnection()
              throws Melding
         Connection dbconn = null;     
         ResourceBundle resBundle;
         try
         Class.forName("com.mysql.jdbc.Driver").newInstance();
         resBundle = ResourceBundle.getBundle("gcoConfig");
         String dbConnectie = resBundle.getString("databaseconnection");
         gcoLogger.debug("lezen databaseconnection in resourceBundle " );
         dbconn = DriverManager.getConnection(dbConnectie);
         } catch (InstantiationException exc)The ResourceBundle is used to read the properties file, named gcoConfig.properties.
    With the getString() command I read the content of the string named databaseconnection.
    The gcoConfig.properties file is placed inside the folder C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\gco\WEB-INF\classes
    The GeneralDao is placed in the folder C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\gco\WEB-INF\classes\org\gertcuppens\cluifDao.
    So this class is placed some folder below the WEB-INF\classes folder of gcoConfig.properties.
    And the content of the properties file is just one line :
    databaseconnection=jdbc:mysql://localhost/cluif
    If you want to let the JSP know what's inside the properties file, wrap the content in a Javabean, put it in the request or even the session and pass the control to the JSP.

  • Weblogic Classpath setting error not able to pick the properties file

    Hi All,
    We are using a third party jar and create a java Web service on the top of that jar. This jar file need two configuration file .properties and .xml when we deploy war for the application into weblogic server it will give file not found error. Though this file already exists inside the .war but from the application it is not able to pick the files.
    We find that these file need to be put in weblogic domain home and we put it there and application works.
    I decompile the jar and found that inside java class they use FileReader("allXXX.xml") path and when I Google it and found that it will pick the file from weblogic domain directory.
    The issue is that we need to put properties file in specific weblogic folder like /3party/config by setting the class path inside startWebLogic.cmd. Please let us know solution for same
    Thanks in advance
    Edited by: sb**** on Mar 19, 2012 9:08 AM

    Hi , I am also facing the similer issue. I am deploying war file of my Spring MVC application , but its not picking resource bundle .properties files from one of the configuration file.
    <bean id="PropertiesRepository"
              class="LanguageBasedPropertiesRepository">
              <property name="propertiesFiles">
                   <map>
                        <entry key="en" value="classpath:/exceptionMessages.properties" />
                        <entry key="es" value="classpath:/exceptionMessages_es.properties" />
                        <entry key="default" value="classpath:/exceptionMessages.properties" />
                   </map>
              </property>
         </bean>
    Please let me know how we can modify this to make it work.
    thanks .

Maybe you are looking for

  • JSP page do not close after loading a file

    Hello, i am having a bit of a problem. i have the following code that help me load reports (pdf and xls) from my server in the user browser. What i do in my code : jsp Page 1(generationInProgress) i create one of these reports (xml with blob) --> jsp

  • How come i received an email confirming my second creative cloud payment 2 days ago and today i have logged on and i only have a free membership?

    about a month ago i signed up to the student creative cloud monthly subscription. today i have bought a new mac book and the first thing i did was install my creative cloud. after logging in and installed illustrator i realised that it had only insta

  • Mail not working on iphone or mac???

    I went on vacation, came home and my mail won't work on my iphone or my mac. It works on my ipad though. I've updated the iphone by connecting to my mac, but still doesn't work! Iphone When I go to the mail button, it says welcome to mail...then give

  • Applications always transfer even when unchecked in itunes!

    I have 2.2.1 firmware and i've just re-installed itunes hoping this would solve my issue, unfortunately it has not. Even though application sync is turned OFF in itunes applications installed from the iphone not itunes always try and transfer to itun

  • CSS equivalent in Swing?

    hi all, i'm trying to standardize all my GUI components in a way such that different containers will be having the same colours for status bars, panel background, etc... i'm thinking of having something similar to webpages' CSS (Cascade Style Sheets)