You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Enrique Marcote Peña <mp...@wanadoo.es> on 2001/09/01 12:13:07 UTC

Tomcat can't open my bd.properties file

Hi:

I have Tomcat 3.2.2 running over Debian Potato and I'm trying to install
a simple JSP application with database access.

I've got a connection pool that works fine when I run it directly with
java. In the root of my classes directory I have a couple of files, a
log file called "ServidorConexiones.log" and the properties file
"bd.properties".

classes/ServidorConexiones.log
classes/bd.properties.log
classes/com/ishop/sql/ServidorConexiones.class
classes/com/ishop/sql/PoolConexiones.class

The source file for the Connection manager is

sources/com/ishop/sql/ServidorConexiones.java

And reads the bd.properties with these sentences...

public class ServidorConexiones {

    /**
     * <p>Nombre del fichero de propiedades empleado para la definición
de los
     * pools.
     */
    static private String properties = "bd.properties";


...MORE CODE HERE...

    /**
     * <p>Constructor privado que inicializa el servidor y todos sus
pools
     * asociados.  Definiendo el constructor como privado se garantiza
el
     * comportamiento Singleton de la clase.  Las demás clases deberán
     * acceder a la instacia del servidor a través del método
     * <code>getInstance</code>.
     */
    private ServidorConexiones() {
        Properties prop = new Properties();
        try {
            prop.load(new FileInputStream(properties));
        } catch (Exception e) {
            System.err.println("Error opening " +  properties + " file:
" + e);
            return;
        }

...CONTINUES...

As I said before, when I run my test applications from de classes
directory directly with java it works fine.  Then, for testing with JSP,
I copy the classes directory to:

jakarta-home/webbapps/isHOP/WEB-INF

After restarting Tomcat, my JSP test application fail opening the
bd.properties file:

Error opening bd.properties file: java.io.FileNotFoundException:
bd.properties (No such file or directory)

What should I do to make this file available for Tomcat?

Any help will be greatly appreciated.  Thanks,

        Quique



Re: Tomcat and Input-Output streams

Posted by Carsten Kaemmerer <ck...@gaertner.de>.
Hello!

> everything works fine.  My question now is, why?  and, where can I get
> some information about Tomcat and the IO files?  I realized that
> Tomcat writes my database log file to "/etc/init.d/" (where the tomcat
> startup script is) I guess that with my previos implementation Tomcat
> searched for the "bd.properties" file in that same directory.  Why
> Tomcat behaves like this?  How can I control the exact location of my
> IO files?

I had similar problems.  tomcat doesn't change his cwd to something
intelligent.  Instead it stays where it is started (/etc/init.d in your
case).

My solution was to change the tomcat-starting script in /etc/init.d:
I simply make an 'cd /to/where/tomcats/cwd/should/be' before starting
tomcat.

You know what I mean?

	Carsten

Tomcat and Input-Output streams

Posted by Enrique Marcote Peña <mp...@wanadoo.es>.
Hello again:

Searching a little bit more I've founded the solution to my problem.
Relying reading of the properties file to a PropertiesManager class with a
method like:

    static {
        try {
            Class propertiesManagerClass = PropertiesManager.class;
            ClassLoader classLoader =
propertiesManagerClass.getClassLoader();
            InputStream inputStream =
                classLoader.getResourceAsStream(PROPERTIES_FILE);

            properties = new Properties();
            properties.load(inputStream);
            inputStream.close();
        } catch (Exception e) {
            System.err.println("Error loading properties from file "
                               + PROPERTIES_FILE + ": "+ e);
            e.printStackTrace();
        }
    }

everything works fine.  My question now is, why?  and, where can I get some
information about Tomcat and the IO files?  I realized that Tomcat writes
my database log file to "/etc/init.d/"  (where the tomcat startup script
is)  I guess that with my previos implementation Tomcat searched for the
"bd.properties" file in that same directory.  Why Tomcat behaves like
this?  How can I control the exact location of my IO files?

Thanks a lot,

        Quique

Enrique Marcote Peña wrote:

> Hi:
>
> I have Tomcat 3.2.2 running over Debian Potato and I'm trying to install
> a simple JSP application with database access.
>
> I've got a connection pool that works fine when I run it directly with
> java. In the root of my classes directory I have a couple of files, a
> log file called "ServidorConexiones.log" and the properties file
> "bd.properties".
>
> classes/ServidorConexiones.log
> classes/bd.properties.log
> classes/com/ishop/sql/ServidorConexiones.class
> classes/com/ishop/sql/PoolConexiones.class
>
> The source file for the Connection manager is
>
> sources/com/ishop/sql/ServidorConexiones.java
>
> And reads the bd.properties with these sentences...
>
> public class ServidorConexiones {
>
>     /**
>      * <p>Nombre del fichero de propiedades empleado para la definición
> de los
>      * pools.
>      */
>     static private String properties = "bd.properties";
>
> ...MORE CODE HERE...
>
>     /**
>      * <p>Constructor privado que inicializa el servidor y todos sus
> pools
>      * asociados.  Definiendo el constructor como privado se garantiza
> el
>      * comportamiento Singleton de la clase.  Las demás clases deberán
>      * acceder a la instacia del servidor a través del método
>      * <code>getInstance</code>.
>      */
>     private ServidorConexiones() {
>         Properties prop = new Properties();
>         try {
>             prop.load(new FileInputStream(properties));
>         } catch (Exception e) {
>             System.err.println("Error opening " +  properties + " file:
> " + e);
>             return;
>         }
>
> ...CONTINUES...
>
> As I said before, when I run my test applications from de classes
> directory directly with java it works fine.  Then, for testing with JSP,
> I copy the classes directory to:
>
> jakarta-home/webbapps/isHOP/WEB-INF
>
> After restarting Tomcat, my JSP test application fail opening the
> bd.properties file:
>
> Error opening bd.properties file: java.io.FileNotFoundException:
> bd.properties (No such file or directory)
>
> What should I do to make this file available for Tomcat?
>
> Any help will be greatly appreciated.  Thanks,
>
>         Quique


RE: Tomcat can't open my bd.properties file

Posted by Wouter Boers <Wo...@MphasiS.com>.
Hi,

You need to loopup the exaxt location of the properties file via the
Class.forname structure. That returns the input stream to the file which you
can then load into the contrucor of the properties.

This is the line that does this:
is =
java.lang.Class.forName("net.ikke.etc.properties.ApplicationProperties").get
ResourceAsStream("/" + DEFAULT_PROPSFILE);

Where the classname is the fully qualified name of the class that tries to
locate the properties file.

Wouter

-----Original Message-----
From: quique@smtp.wanadoo.es [mailto:quique@smtp.wanadoo.es]On Behalf Of
Enrique Marcote Peña
Sent: 01 September 2001 12:13
To: Tomcat-user mailing list
Subject: Tomcat can't open my bd.properties file


Hi:

I have Tomcat 3.2.2 running over Debian Potato and I'm trying to install
a simple JSP application with database access.

I've got a connection pool that works fine when I run it directly with
java. In the root of my classes directory I have a couple of files, a
log file called "ServidorConexiones.log" and the properties file
"bd.properties".

classes/ServidorConexiones.log
classes/bd.properties.log
classes/com/ishop/sql/ServidorConexiones.class
classes/com/ishop/sql/PoolConexiones.class

The source file for the Connection manager is

sources/com/ishop/sql/ServidorConexiones.java

And reads the bd.properties with these sentences...

public class ServidorConexiones {

    /**
     * <p>Nombre del fichero de propiedades empleado para la definición
de los
     * pools.
     */
    static private String properties = "bd.properties";


...MORE CODE HERE...

    /**
     * <p>Constructor privado que inicializa el servidor y todos sus
pools
     * asociados.  Definiendo el constructor como privado se garantiza
el
     * comportamiento Singleton de la clase.  Las demás clases deberán
     * acceder a la instacia del servidor a través del método
     * <code>getInstance</code>.
     */
    private ServidorConexiones() {
        Properties prop = new Properties();
        try {
            prop.load(new FileInputStream(properties));
        } catch (Exception e) {
            System.err.println("Error opening " +  properties + " file:
" + e);
            return;
        }

...CONTINUES...

As I said before, when I run my test applications from de classes
directory directly with java it works fine.  Then, for testing with JSP,
I copy the classes directory to:

jakarta-home/webbapps/isHOP/WEB-INF

After restarting Tomcat, my JSP test application fail opening the
bd.properties file:

Error opening bd.properties file: java.io.FileNotFoundException:
bd.properties (No such file or directory)

What should I do to make this file available for Tomcat?

Any help will be greatly appreciated.  Thanks,

        Quique