Joe,

I am not sure if there is any magic in .ini or .properties, but if you

use a property file, you should be able to load it from your
WEB-INF directory with the application class loader. For
resources retrieved using a URL, the docBase will be where
you start.

I use Struts, which has a handy feature that allows you to configure
helper files like your .ini file. I looked at the source to see how
they
configure it and it looks like Tomcat sets the base directory from
the docBase, and then everything is relative to that. In Struts you
get an ActionMapping object that you can retrieve the application
path or resources. Those defined resources are built on startup or
change as a hashmap. I just let Struts handle the dirty work and use
what it hands me. It works for both XML and properties files. It is all

open source so you can see exactly what the code is doing.

David Morris


>>> joepluta@PlutaBrothers.com 05/13/02 01:50PM >>>
> Joe,
>
> Tomcat 4.0 follows the Servlet 2.3 and JSP 1.2 specifications
> exactly and is the reference implementation. That is why you
> won't find any "extensions". To specify a directory outside of
> your webapps directory, you need to set up a context in your
> server.xml file that is not relative like:
>
> <Context path="myapp" docBase="/myapp" debug="0" />
>
> The docBase does what you need. In this case a url like:

David, this is actually a different issue.  I'm not worried about
trying to
redirect my document base; that is already done.  The documents come
from
within the Tomcat folder as needed.  In my server.xml, I have the
following:

        <!-- Tomcat Root Context -->
        <Context path="" docBase="ROOT" debug="0"/>

This gets all my JSP, HTML and so on served from folders under ROOT.
I'm
pretty sure this is the default, also, but I decided to explicitly
identify
it.

The problem arises when I attempt to do something like this in my
servlet:

File file = new File("myprops.ini");

I am trying to open a .ini file.  In this case, standard Tomcat points
me
back to the root of the IFS.  Now, on both WebSphere and on the Apache
version of Tomcat I can specify the root for File objects by using the
"ServerRoot" directive, but there is no equivalent in Tomcat
standalone.

Try this in a servlet:

        String[] files = { "file", "/slashfile", "./dotfile",
"/./slashdotfile" };

        out.println("<H4>File paths</H4>");

        out.println("<table border=4>");
        out.println("
<tr><th>AbsoluteFile</th><th>AbsolutePath</th><th>CanonicalFile</th><th>Cano
nicalPath</th></tr>");

        try {
                for (int i = 0; i < files.length; i++)
                {
                        File file = new File(files[i]);
                        out.println("  <tr><td>" +
                                file.getAbsoluteFile() + "</td><td>" +
                                file.getAbsolutePath() + "</td><td>" +
                                file.getCanonicalFile() + "</td><td>" +
                                file.getCanonicalPath() +
"</td></tr>");
                }
        } catch (Exception e1) {}

        out.println("</table>");

This code will print out the results of the absolute and canonical
files and
paths for files with various types of addressing.  When you run this
under
WebSphere and under Apache/Tomcat, the two relative files ("file" and
"./dotfile") give values with the ServerRoot prepended, such as
"/www/apachetest/file"), while with Tomcat standalone, they start at
the
root of the IFS ("/file"), regardless of the docBase.

Because of this, I would have to hardcode in the entire absolute path
to
Tomcat in order to access my .ini file, which makes it very difficult
to set
up multiple instances with different properties.

I hope this makes sense.  It's a crucial issue when trying to set up
configuration files.

Joe


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.