Properties files with Tomcat 4.0.1

I'm having trouble finding properties files using Class.getResourceAsStream
Properties props = new Properties();
try {
  props.load(Class.class.getResourceAsStream("/Database.properties"));
catch (IOException e) {
  //error reading from stream
}The above code works fine on several web server (including Tomcat 3.2.3), but fails on Tomcat 4.0.1 - the server takes around 50 seconds to return a response, then throws a StackOverflowError. The properties file is in WEB-INF/classes.
Has anybody else had the same problem?

Thanks for the reply Guido.
However, I can't use the ServletContext to load the files I'm after, because the code is part of the data tier and should not be dependent upon the controller (in fact I have no reference to the ServletContext).
If I can't use Class.getResourceAsStream in Tomcat 4, does that mean that any third party APIs that rely on it will fail? - seems a little strange to me!
The Tomcat 4.0 documentation says:
"All unpacked classes and resources in the /WEB-INF/classes directory of your web application archive, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others."
I would expect "All unpacked classes and resources" to include all unpacked resources (such as properties files)
I've now managed to load the properties file using this code:
props.load(new FileInputStream(getClass().getResource("/Database.properties").getFile()));(don't know why getResource should work when getResourceAsStream doesn't, but that's what appears to be happening).
Now I have a new problem - loading a JDBC driver. I get:
java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
when I call
new OracleConnectionCacheImpl()
but the class does exist, in a zip file (OracleThinClientJDBCDriver_901.zip) in WEB-INF/lib. It looks to me like the oracle code in the lib directory has been found by the ClassLoader, but that Class.forName does not work...eh?!?

Similar Messages

  • Updating properties file with values containing characters like slash (/)

    Hi,
    I am writing a java class that would create/update properties file. I am passing a string that contains colons. e.g. a path like
    http://xyz.com
    I am using the java.util.Properties.setProperty(String arg0, String arg1) method to set the key value and the java.util.Properties.store(OutputStream arg0, String arg1) to create/update the properties file.
    The resulting property file contains the value as http\://xyz.com
    A slash preappended to the colon.
    I do not want this slash to be preappended.
    How can I achieve that?

    If you don't want this escaping to happend, then you don't want to be using java.util.Properties. Those define the file format in a certain way that includes escaping those characters.
    If you don't want this, you'll have to write them using normal Writers (and read them using Readers) with your own parsing/storing logic added.

  • Problem in web services wsdl file with tomcat 5

    Hi to all JGurus,
    I am sunil, i have one problem with simple web service, i made a simple web service and deployed on my tomcat 5, my tomcat showing the web service but when i click on the wsdl link it throws the exception:
    javax.servlet.ServletException: JAXRPCSERVLET35: failed to create a template object
         com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGetDefault(JAXRPCServletDelegate.java:351)
         com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doGet(JAXRPCServletDelegate.java:157)
         com.sun.xml.rpc.server.http.JAXRPCServlet.doGet(JAXRPCServlet.java:111)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    please help me, thanks in advance.

    Hi Rama,
    I used JAX-RPC with WSDp 2.0 first i created my interface then implemented class then i have used the wscompile to generate wsdl. then i packed with jaxrpc-ri and web.xml in a war file, this raw war file i used to generate my original final war with the help of wsdeploy command.
    I deployed this file on tomcat its showing the service but while clicking on wsdl link it throws the above exception.
    Please let me know any thing else u want to know i can fwd my sample war file also to u.
    Thanks in advance.
    Sunil

  • Properties-file with a relative path...

    Hello everybody,
    my question is as follows:
    I have a directory-structure like below:
    root_dir
    |
    -- source
    |
    -- classes
    |
    -- libs
    |
    -- xmlfiles
    |
    myproperties.propsIn words: my root_dir (is actually a subdirectory in my fs) contains folders like source (java-files), classes (class-files)... and a properties-file myproperties.props. The source-dir has subdirs like com/xyz/bla/Mainclass.java...
    I want to load the properties-file from the main-class, but without using the absolute path. That's the way I do it at the moment:
    Properties props = new Properties();
    props.load(new FileInputStream("d:\\foo\\something\\root_dir\\myproperties.props"));But I don't want to write the whole path, because of portability (forget the \\ :) )!
    How can I obtain the root_dir?
    Thanx for helping!
    Regards, Robert4

    Well I was already working on a replacer for /../ stuff before I was pointed to the File class. Not the best code I've written, but works fine. Perhaps it could be of use to you.
        public void setCoordinatesFileURL(String coordFileURL)
            coordinatesFileURL=coordFileURL;
            //replace .. to get canonical path
            StringTokenizer st = new StringTokenizer(coordinatesFileURL,"/");
            String[] stringURL= new String[st.countTokens()];
            int teller=0;
            while(st.hasMoreTokens())
                String token=st.nextToken();
                if(!token.equals(".."))
                    stringURL[teller]=token;
                    teller++;
                else
                    teller--;
            coordinatesFileURL="";
            for(int i=0; i<teller-1;i++)
                coordinatesFileURL+=stringURL[i]+"/";
            coordinatesFileURL+=stringURL[teller-1];
        }

  • One Log File With Tomcat

    I am trying to figure out how to get all of my logging to use one log file. Currently when I start tomcat as a service it writes to stderr.log, stdout.log as well as a log file I have configured using Log4j. I would like all logs including startup/shutdown logs that are currently going to stdout.log/stderr.log to go to the file I write to using Log4j.
    If I start tomcat using catalina.bat it doesn't do this (bc it writes to the console window) but I would like to send all those startup/shutdown messages to the log that Log4j uses if I start tomcat as a service.
    Any help would be appreciated.

    That doesn't really help, because I've got Log4j already running. It looks like there is no easy solution to this. I'm left with choosing one of the three options below.
    1) Configure a <Logger> element for the Context that catches any logging not sent to the Log4j log file. This means I would have a stdout.log, stderr.log, log from the <Logger> element, and a log for Log4j. That's a lot of log files...
    2) Not configure a <Logger> element for the Context. This means any logging not sent to the Log4j file will go to either stdout.log or stderr.log. Those files could get big and aren't rotated like my Log4j file. Not exactlly ideal either.
    3) Don't install Tomcat through the .exe file. Unpackage it, set the environment variables, and set it up as a serivce through a script such as the one mentioned at http://weblogs.java.net/blog/simongbrown/archive/2003/09/installing_tomc.html setting the same file that Log4j uses for the -out and -err parameters. This means that all logging (startup/shutdown) will go to this one log file. But it also means messing with the install (deviating from the .exe) which scares me a little.
    Unless someone has a better idea...I guess it's one of the three above.
    Thanks,
    Jim

  • Creating links to text files with Tomcat and JSP

    I am trying to create links in a JSP page that bring up text files. Currently, the links point to a file format. When the links are clicked, however, the text files are not displayed in the web browser. When an "http:" format is used, the links point to terminal files that are not being written dynamically (and therefore are useless to me). So in short, I'm looking for a way to get these links to (1) point to text files on the network, and (2) get them to display in a new browser window. Any help or guidance will be greatly appreciated.
    Thanks.
    TGD

    You cannot expect Tomcat or any J2EE Server to give access to the Network files.
    You need to design a different way to give access to the Users.
    What you can do is write a proxy (HttpServlet) which can pass a request parameter as the file name. The Servlet can read the file and then paint it in the Client Browser Window.
    Hope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • [Deploy WAR File with Tomcat]  Blank page  after login to DSCC

    i installed Sun Java System Directory Server Enterprise Edition 6.3 ( Zip Distro) in SuSe Linux 10 sp2 (64bit )
    and I've deployed DSCC web console in tomcat with following installation guide
    http://docs.sun.com/app/docs/doc/820-2761/6nebf1543?a=view
    open browser , go to http://hostname:8080/dscc, The Directory Service Manager Login page displays.
    i entered username/password , after that, nothing come up in the page...
    Anyone got idea ?
    Edited by: ikcat on Jan 16, 2009 12:06 AM

    Usually restarting Tomcat will help. Do the Tomcat logs have anything of interest?

  • File I/O problems using a Properties file

    Hi,
    I am having troubles reading in a properties file. The file looks like this:
    aname=apassword:word2
    bname=bpassword:word
    ...etc
    The code I have this far is:
    import java.util.*;
    import java.io.*;
    public class LoginH
    public static void main(String[] args)
    String logon, pswd;
    //String login = null;
    //String password = null;
    //String nick = null;
    int msg = 0;
    System.out.print ("Login: ");
    logon = MyInput.readString();
    System.out.print ("Password: ");
    pswd = MyInput.readString();
    Properties settings = new Properties();
    try
    FileInputStream sf
    = new FileInputStream("LogonH.ini");
    settings.load(sf);
    catch (FileNotFoundException e) {}
    catch (IOException e) {}
    // public void whitespaceChars(58,58)
    StringTokenizer st = new StringTokenizer(settings.getProperty(logon));
    String password = st.nextToken();
    String nick = st.nextToken();
    System.out.print (password + nick);
    ** It works fine if i replace the colon in my properties file with a blank space, However i need to use a colon. I tried to set whitespaceChar to allow this but I can not seem to get it to work. Let me know if you have any ideas. Thanks in advanced.

    Thanks. I just got done doing something to that nature however now my problem is if the key field is not in my properties file my program crashes. I need to print out to the console "sorry" if my user name which is my key is not in the properties file. Here is my code if anyone can help me out:
    import java.util.*;
    import java.io.*;
    public class LoginH
    public static void main(String[] args)
    //******** Declare Variables *********************
    String userlogin;
    String userpaswd;
    String login = null;
    String paswd = null;
    String nicknm = null;
    int match=0;
    String delim = ":";
    //******** Get username and password **************
    System.out.print ("Login: ");
    userlogin = MyInput.readString();
    System.out.print ("Password: ");
    userpaswd = MyInput.readString();
    Properties settings = new Properties();
    try
    FileInputStream sf = new FileInputStream("LogonH.ini");
    settings.load(sf);
    catch (FileNotFoundException e) {}
    catch (IOException e) {}
    StringTokenizer st = new
    StringTokenizer(settings.getProperty(userlogin),delim);
    paswd = st.nextToken();
    nicknm = st.nextToken();
    if(userpaswd.equals(paswd))
    System.out.println("Ok " + nicknm);
    match = 2;
    else
    System.out.println("Sorry " + nicknm);
    match = 1;
    if (match == 0) System.out.println("Sorry");
    }

  • How to configure boe.properties file in ACTool for SAP BO Distributed environment

    Hi ,
    I am trying to configure the ACTool for SAP BO distributed environment (dedicated BOE Server, Tomcat and Explorer) servers. I have installed SMD Agent, Host Agent and ACTool without any issues in the BOE server(CMS), but I am unable to run the ACTool in Tomcat Server(Web Tier)  and Explorer servers.
    1. How can we configure the boe.properties file for Tomcat Server and Explorer ser to run ACTool?
    2. Is it required to install SMD_Agent and Host_Agent  in Tomcat Server and Explorer server (in my case i have already installed).
    3. What all parameters need to be set in boe.properties file so that ACTool will run correctly in Tomcat server and Explorer server correctly.
    Regards
    Pramod

    Hi ,
    I am trying to configure the ACTool for SAP BO distributed environment (dedicated BOE Server, Tomcat and Explorer) servers. I have installed SMD Agent, Host Agent and ACTool without any issues in the BOE server(CMS), but I am unable to run the ACTool in Tomcat Server(Web Tier)  and Explorer servers.
    1. How can we configure the boe.properties file for Tomcat Server and Explorer ser to run ACTool?
    2. Is it required to install SMD_Agent and Host_Agent  in Tomcat Server and Explorer server (in my case i have already installed).
    3. What all parameters need to be set in boe.properties file so that ACTool will run correctly in Tomcat server and Explorer server correctly.
    Regards
    Pramod

  • @WEBLOGIC in properties file

    Hi,
    What am I supposed to replace this. My weblogic is installed
    on drive E: on NT.
    E:\weblogic
    However, when I didn't replace, and tried to access the cloudscape
    DB, I noticed that a directory @WEBLOGIC was created in
    E:\weblogic !
    Should I just replace @WEBLOGIC in the weblogic.properties file
    with empty string?
    Thanks,
    Andy

    I don't believe that feature is available until 6.1.
    Peace,
    Cameron Purdy
    Tangosol Inc.
    << Tangosol Server: How Weblogic applications are customized >>
    << Download now from http://www.tangosol.com/download.jsp >>
    "Kevin White" <[email protected]> wrote in message
    news:3b89b178$[email protected]..
    >
    Does anyone know if Weblogic 5.1 has a way to encrypt the Databasepassword that
    is stored in the weblogic.properties for DB pools. System Administratorsusually
    do not have access to database passwords. Also, there is a security riskin having
    a production password in the clear. If Weblogic 5.1 doe not have thiscapability,
    then has anyone done a work around to resolve this issue?
    Thanks,
    Kevin White

  • How to set 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

    I am using the propeties file to get the SQL statements. I have all the SQL query statement in the properties file. I am creating a preparedstatement after getting the statement from the properties file with the id like we do in ResourceBundle. If I keep the properties file in the config directory of the Sun App Server instance , then it is working fine. But If I don't keep it there, then it is giving me a file not found exception.
    My SQL class which is accessing the properties file are in same package (com.company.sql). But still it is not able to find the file. As suggested by you, I tried it by giving the path as com.company.sql.SQL. Still it did not found the file. The file is there inside the WEB-INF/classess/com/company/sql/.
    Thanks
    Amit

  • Properties file not accessible for older requests

    Hi
    With use of jar file as external resource, we are making use of some properties from properties file.
    Whenever we update the properties file with new properties, after deploying the project - it is observed that for old requests the newly added property is not available.
    And in the code, we are accessing the new property which is producing exception when an older request refer to this piece of code.
    does it make sense or there might be some other problem that is causing the exception??
    (missingresourceexception is the exception thrown - it is referring to the new property entry in the logs as it cannot find a property for that)

    Hi Anuj,
    We are putting it in jar file itself. This jar file is added in external resources.
    The current situation is - the change is getting reflected for new (request) instances getting created. For already existing instances, it is not.
    by the way, on enterprise server, where can we locate the contents of jar - so that we may modify at run-time... or no such provision is there.
    Thanks for your quick response.
    Regds,
    Sharma

  • How to create an Object array(two dimensional) from a properties file..

    Hi All..
    I have a typical problem..
    I have a properties file with key/value pairs . Now what I want to do is.. I need to read all the keys and the values corresponding to that keys and then create a two dimensional array.. Like..
    Properties props;
    Object[][] contents;
    My contents should be like
    contents = {{key1,value1},{key2,value2},{key3,value3},...};
    Can someone tell me how to do this.. asap...
    TIA
    CK

    Just because something is difficult for you does not qualify it as an "Advance Language Topic"... And it certainly doesn't allow you to multi-post.

  • Problem storing special characters (\, \n etc.) in the Properties file

    Hello,
    I am trying to store a string that contains special characters like \, \n, which are normally escaped using a \ character. If I try to save the Properties object into a file (using the store() method call), it doesn't store these escape characters as they are. The following is what I am trying to do:
    Properties p = new Properties();
    String samp = "This string will have a \\ and a newline \ncharacter";
    p.setProperty( "sample", samp );
    p.store( new FileOutputStream( "/path/to/my/file" ) );I am trying to achieve the following result:
    sample=This string will have a \ and a newline
    characterBut, instead, I get this:
    sample=This string will have a \\ and a newline \\\ncharacterCan somebody help me with this problem?
    Thanks,

    Thanks for your replies and efforts to help me out. I
    guess there is no solution to my unique problem.
    Basically I need this because one of my values (for a
    key) is a multi-line value. It will probably load
    fine when I use the \ character to delimit multiple
    lines, but when I want to write back the same value
    as multiple lines (using \ and \n characters), I am
    unable to do that. I don't follow, or else if you're saying what I think you are, I disagree.
    Let's say you have a String in your program that contains some \n characters, so if you print that string, say with println, on a Unix terminal, you'll see it on separate lines.
    Now you write that string out to a properties file with store().
    Forget how it looks in the props file. Consider that opaque, a black box.
    Now you use load() to get it back from the properties file. It will be re-created in its original form, so if you print it out on a unix terminal, you'll again see multiple lines. The fact that it's all on one line in the .properties file doesn't affect that.
    Now, if you want it to appear on multiple lines in the props file, then we're back to my previous post--you're breaking the format that load expects.
    At least, that's my understanding of how it works. I might be mistaken, but I think I've tested this very thing in the not-too-distant past.

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

Maybe you are looking for

  • Background processing

    hi all!!!!!!!   i have made one ALV report , with one pushbutton on application toolbar , whenever tht is clicked , PAI event is triggered and another LIST is displayed .   This is performing as required . Now user wants , whenevr report is being exe

  • I'm using Adobe Photoshop CS5 Extended and am having trouble with it.

    I just reinstalled Photoshop CS5 Extended from my original disk because I was having trouble with it. I did do an uninstall before installing. Every time I quit Photoshop I get this message: "Could not save Preferences because the file is locked or y

  • Mute Switch after upgrading to iOS 4.3.3

    Anyone encountered problem with the Mute switch on Apple iPad after updating to OS 4.3.3?  Set lock rotation, functioned as advertised. Set mute still got sound even switched on. A few of my colleagues also got this issue. BTW, mine is iPad 1.

  • Segmentation fail in gtk/gnome programms

    When I start a GTK application, it doesn't run well and when I execute it from terminal, this error appears (example with mahjongg, from the package gnome-games) 2$ mahjongg (mahjongg:21263): GLib-GObject-WARNING **: specified class size for type `Ma

  • Sort an XMLList on an attribute value?

    How do you sort an XMLList (or XMLListCollection) on an attribute value rather than the element content? Thanks, ...scott